I keep getting seg fault and I don't know why, if someone could help me with this it would be great. I cannot find the error here............
I get all the print states up till the end of the the first four loop
i however do not get the "out" print statement,, thats where the set fault is
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void getWords(int arg, char** argWords, Words* words);
void getWords(int arg, char** argWords, Words* words)
{
printf("In Method\n");
int ewm=1;
for(ewm =1 ; ewm<= arg; ewm++){
int tempr = (strlen(argWords[ewm]) +1);
printf("tempr: %d\n", tempr);
words->numWords = words->numWords + tempo;
printf("numWords: %d\n", words->numWords);
printf("in\n");
}
printf("out\n");
printf("%d\n", words->numWords);
int x = 1;
int y = 0;
printf("four loop\n");
for(x= 1; x<=arg; x++){
printf("SIZE: %d\n", (strlen(argWords[x] )+1));
char* temp = malloc(strlen(argWords[x])+1);
printf("%s\n", argWords[x]);
}
}
//*****************************//
int main(int argc, char** argv){
if(argc == 0){
printf("Please input a value/n");
return 1;
}
Words *currWords = malloc(sizeof(Words));
printf("Mem located\n");
getWords(argc, argv, currWords);
return 0;
}
for(ewm =1 ; ewm<= arg; ewm++){ int tempr = (strlen(argWords[ewm]) +1); printf("tempr: %d\n", tempr); words->numWords = words->numWords + tempo;— what istempo? Does the code compile? And how is the structure typeWordsdefined? Also, C arrays normally start at index 0, fo you normally usefor (ewm = 0; ewm < arg; ewm++)rather than what you wrote.