C -> sizeof string is always 8 -
#include "usefunc.h" //don't worry -> lib wrote int main() { int i; string given[4000], longest = "a"; //declared new typdef. equivalent 2d char array given[0] = "a"; printf("please enter words separated rets...\n"); (i = 1; < 4000 && !stringequal(given[i-1], "end"); i++) { given[i] = getline(); /* if (sizeof(given[i]) > sizeof(longest)) { longest = given[i]; } */ printf("%lu\n", sizeof(given[i])); //this returns eight!!! } printf("%s", longest); }
why return 8???
there no string
data type in c. c++? or string
typedef?
assuming string
typedef char *
, want strlen
, not sizeof
. 8 getting sizeof
size of pointer (to first character in string).
Comments
Post a Comment