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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -