Adding the '-' doesn't work. Please advise. Thank you.
char keys[100][30];
. . .
Code:void printData(void) { int x = 0; strcat(keys[x],"-"); for(x = 0;x<cntr+1;cntr++) puts(keys[x]); }
Adding the '-' doesn't work. Please advise. Thank you.
char keys[100][30];
. . .
Code:void printData(void) { int x = 0; strcat(keys[x],"-"); for(x = 0;x<cntr+1;cntr++) puts(keys[x]); }
Code:strcat(keys,"-"); //keys[x] = '-'
Last edited by Structure; 01-28-2020 at 09:31 AM.
"without goto we would be wtf'd"
You don't tell us what's in keys to begin with, and
strcat(keys[x],"-");
is only going to append a - to the FIRST one anyway.
> void printData(void)
A poorly named function if it goes around modifying things.
What if you want to call it several times?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Hallo Ivory348
Look at line 5:
[code]
for(x = 0;x<cntr+1;cntr++) puts(keys[x]);
[code]
The integer 'x' has always the same content.
It can't get bigger.
The validity of 'x' is only for the function printData:
example:
Code:#include <stdio.h> #include <string.h> #define NUMBER_OF_KEYS 15 void printData(char keys[NUMBER_OF_KEYS][30]) { int x = 0; for(x = 0; x < NUMBER_OF_KEYS; x++) { strcat(keys[x],"-"); puts(keys[x]); } } void printData_b(char keys[NUMBER_OF_KEYS][30], char *test) { int x = 0; for(x = 0; x < NUMBER_OF_KEYS; x++) { strcat(keys[x],test); puts(keys[x]); } } int main(int argc, char **argv) { char keys[NUMBER_OF_KEYS][30] = {0}; printf("strcat-test\n"); printData(keys); printData_b(keys, "Tica'ti'bu"); return 0; }