I'm trying to pass a char[] to a function however every time that I try to it loses it's value. I can pass it to other functions, but when I pass it to one specific one it just loses the string stored in the array. code follows:
int test(char one[], int len) {
printf("The string: %s, The size: %d", one, len);
int to = rd_field_length(one, 0, len);
return to;
}
int main(){
rd_open("thefile");
char line[200] = "";
double d;
int * err;
int c, length = 0;
if(fp != NULL) {
while((c = rd_getchar()) != EOF && c != '\n'){
line[length] = c;
length++;
}
}
int to = test(line, length);
}
int rd_field_length(char buf[], int cur, int end ){
printf("BUF: %s", buf);
return 0;
}
Line gets passed to test and I can access the string, however when passing to rd_field_length it loses it's value.
char line[200] = {0};to initialize the entire array to 0. Or addone[len] = 0at the beginning oftest()