c - ERROR: variable "string" is not initialized -
i wrote code reads .txt string , settles in char *, gives me error variable "string" not initialized, if initialized inside fscanf, can u tell me wrong? thanks!
char *string; file *fp = fopen("words.txt", "r"); fscanf(fp, "%s", string);
that's normal, didn't allocate string. c needs allocate in memory before use it. have know size.
in code, string points memory doesn't exist (to exact points somewhere have lot of chance can't access it)
see how malloc works.
Comments
Post a Comment