Please tell me why iam always getting “Server Upload Failed!” in the code
given below.
int rval = 28;
char *return_str=NULL;
return_str = strdup((rval!=28) ? ("Server Upload Failed!") : ("Server TimeOut Reached!"));
printf(" return_str : %s\n", return_str);
Output that iam getting is ====> Server Upload Failed! . I want to know why it is not giving
"Server TimeOut Reached!" as output .
Platform : Linux , gcc-compiler
It looks correct to me, once I read it a couple of extra times. It should generate the latter string (“Server TimeOut Reached”).
Not sure why you would ever need to call
strdup()on a static string, instead of just using the literal directly. One case would be if there sometimes a need for a more dynamic string I guess, so whoever receives the value assumes it’s dynamic and takes ownership.