anonymous
  • anonymous
can any1 pls check this code and tell if ther's anythin wrong?
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
void copy(char **array,char name[10]) { FILE *fp; fp=fopen(name,"r"); char c; int i=0,j=0,flag=0,m=0; while((c=getc(fp))!='\n') { if(c==' ') { flag++; if(flag==1) { m=0; array[i][j]=' '; j++; } else if(flag==3) { j=0; array[i][j]='\0'; i++; flag=0; fseek(fp,-m,1); } } else { array[i][j]=c; j++; } m++; printf("%c %c\n",array[i][j],c); } fclose(fp); return; }
anonymous
  • anonymous
it is supposes to copy groups of three words into a 2d array... @farmdawgnation
anonymous
  • anonymous
ex: this is a test file this is a is a test a test file

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

farmdawgnation
  • farmdawgnation
Are you seeing a problem with the code as is? Knowing what's wrong would help.
anonymous
  • anonymous
like array[i][j] and c prints different characters and array[i][j] prints garbage values
anonymous
  • anonymous
this is the total code if u wanna run #include #include #include //int length(char name[10]); char** makeArray(int n); void copy(char **,char name[10]); //void compare(char **array,char name[10],int x); //int count(char name[10]); main() { int k=0,x; char name[10]; printf("enter the name of the file:"); scanf("%s",name); int i,j,comp[10]; char **array; x=length(name); array=makeArray(x); copy(array,name); /*for(j=0;j
farmdawgnation
  • farmdawgnation
You're never allocating memory for array for starters.
farmdawgnation
  • farmdawgnation
Ah.
anonymous
  • anonymous
i did and passed the array as an argument r8
farmdawgnation
  • farmdawgnation
Yowza segmentation fault.
farmdawgnation
  • farmdawgnation
You're doing something you're not supposed to :P
anonymous
  • anonymous
i dint get any segmentation fault
farmdawgnation
  • farmdawgnation
``` enter the name of the file:testfile the number of phraes:3,max size of word:7 3007 ? t 2 h ? i ? s  i s , a i s a t e s t a t e s t f i l e Segmentation fault: 11 ```
farmdawgnation
  • farmdawgnation
BTW. Single letter variable names suck. :P
farmdawgnation
  • farmdawgnation
Yeah man, I'm not sure what's going on. I don't really feel like spending three hours with gdb digging into it to figure it out. I don't really have that much free time atm. :/
farmdawgnation
  • farmdawgnation
FWIW I don't see anything obvious.
anonymous
  • anonymous
hmmm thanks anyway....if u find anythin lemme kno
anonymous
  • anonymous
lol not a bigg thing....the print statement was showing some random values coz.... of j!!! ie the next character that's not copies yet!!
anonymous
  • anonymous
nd that xplainds the seg fault too

Looking for something else?

Not the answer you are looking for? Search for more explanations.