c - how can i access arrays outside a while loop -



c - how can i access arrays outside a while loop -

how can access array outside loop populated within while loop ?

main.c

#define _crt_secure_no_warnings #include "definition.h" #include <stdio.h> #include <string.h> #include <pthread.h> extern int readline(),countword(); char line[500]; /* 1 line file */ char myfilelist[300][maxline]; char myfilelist2[300][maxline]; char myfilelist3[300][maxline]; char myfilelist4[300][maxline]; int nchars = 0, /* number of characters seen far */ nwords = 0, /* number of words seen far */ nlines = 0, /* number of lines seen far */ linelength; /* length of current line */ void *threadtask(void *threadarg) { //receive array //match each element file name in directory //perform counts on each file //print store or homecoming values //printf("%s",myfileslist); } file *filep; int main(int argc, char **argv) { int = 0; filep = fopen(argv[1], "r"); if (!filep){ printf("no %s such file found\n", argv[1]); homecoming -1; } while ((linelength = readline(filep))!=0) //here in loop split big file 4 arrays depending on number of lines(240). how can access these newly created arrays outside while loops. need pass them individual threads arguments. { if(i>=0 && i<60){ strcpy(myfilelist[i], line); printf("%s\n", myfilelist[i]); i++; } if(i>=60 && i<120){ strcpy(myfilelist2[i], line); //printf("%s\n", myfilelist2[i]); i++;} if(i>=120 && i<180){ strcpy(myfilelist3[i], line); //printf("%s\n", myfilelist3[i]); i++;} if(i>=180){ strcpy(myfilelist4[i], line); //printf("%s\n", myfilelist4[i]); i++;} } fclose(filep); }

readline.c

#include "definition.h" #include "externalvar.h" #include <stdio.h> int readline(file *filep) { //please implement code here int = 0; char ch; while (!feof(filep) && i<maxline){ ch = fgetc(filep); if (ch == '\n'){ break; } line[i] = ch; i++; } line[i] = 0; homecoming i; }

whats easiest way pass 4 arrays created in while loop threads arguments? every time seek print out arrays outside of while loop there nil , when seek print them out within while loop outside if loops display 1st line 60 times.

if using pthreads utilize lastly parameter of pthread_create() pass argument tread-function.

c arrays

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -