Newbie here, Access programmer VBA for years but trying to learn "C" is killing me!
Simple start of book exercise,
Using "GCC" compiler
What my code should do:
Read each keyboard entry into Array called "Words"
Keep accepting keyboard entries until the word "Devo" then print out each entry within the "Word" array then terminate.
When I run it I can enter the first value "hello World" and all is well, when I enter the second word "Bacon" it crashes with ugly non descriptive error messages.
I THINK it is crashing at the statement
strcpy(words[size],temp);
after I have entered "Bacon" as my second entry.
Am I declaring my Array incorrectly? The concept is a bit foreign as I tend to think in "Tables", "Records" and "Fields"
Why is it not accepting additional entries?
Thank you!
Output
Crashes after the second word entered via keyboard "Bacon
Simple start of book exercise,
Using "GCC" compiler
What my code should do:
Read each keyboard entry into Array called "Words"
Keep accepting keyboard entries until the word "Devo" then print out each entry within the "Word" array then terminate.
When I run it I can enter the first value "hello World" and all is well, when I enter the second word "Bacon" it crashes with ugly non descriptive error messages.
I THINK it is crashing at the statement
strcpy(words[size],temp);
after I have entered "Bacon" as my second entry.
Am I declaring my Array incorrectly? The concept is a bit foreign as I tend to think in "Tables", "Records" and "Fields"
Why is it not accepting additional entries?
Thank you!
Code:
int main(){
char *words[100];
char *temp;
int i = 0;
int size = 0;
do{
gets(temp);
strcpy(words[size],temp);
size++;
}while(strcmp(words[size - 1], "devo") != 0 && size < 100);
for(i = 0; i < size; i++){
printf("%s\n", words[i]);
}
return 0;
}
Output
Code:
[3:31:23 PM] poduskas: C:\Users\Poduska>a
hello world
bacon