Linux code issue

Hi there, i have some problems with 2 parts of code that on a win machine is working just fine-
1
2
3
4
char nl[32], cl[32], il[32], sl[32], pl[32];
      FILE *fl=fopen("f.txt","r"); fscanf (fl,"%s\n%s\n%s\n%s\n%s",&nl,&cl,&il,&sl,&pl);
        if( (strcmp(nl, "")!=0) && (strcmp(nl, " ")!=0) && (strcmp(cl, "")!=0) && (strcmp(cl, " ")!=0) && (strcmp(il, "")!=0) && (strcmp(il, " ")!=0) && (strcmp(sl, "")!=0) && (strcmp(sl, " ")!=0) && (strcmp(pl, "")!=0) && (strcmp(pl, " ")!=0) ) {
            printf("%s %s %s %s %s); } 

Well here the if statement became true although that file is empty and there are printed some funny chars .. why?
And also at this part i get a segmentation fault-
1
2
3
4
5
for(ii=1; ii<=dd; ii++) {                                                      
    sprintf(fn, "tdir/file%i.txt", ii);                                         
    FILE *f2=fopen(fn,"w");                                                 
    fprintf (f2,"val1 %s\nval2 %s");
    fclose(f2); }

Where is the problem?
Last edited on
The second one resolved, was just a problem of writing permisions in that folder lol.
What about the first one?
And 1more thing, at the end of the program how to destroy/empty/free the memory used by my program?
Last edited on
Line 4 - using %s but not giving any additional parameters.
Missing only here, sorry.
Found the problem for the first one, i have defined those chars + rest of them before main() and now it's fine .. maybe some memory realocation issue.
Last edited on
Topic archived. No new replies allowed.