I am very new to C. I writing some code to try and separate a stdin string by commas, but I am not sure how to best do this.
Basically, I have some data that will be typed in by the user in the following format:
UserID (char[]), 00:00:00 (for time,(char[]), MeasurementID (char[]), readingValue (double)
I need to separate out these values so that I can assign them each to a variable. I have some code written where I have attempted to do this, however, I know that it is not quite right.
char buffer [1024];
char input[];
scanf("%s", input);
int temp = 0;
int timekeeper = 0;
char userID[];
char timestamp[];
char measurementID[];
double value;
for(temp = 0; temp < sizeof(input); temp++){
char val[1024];
while(input[temp] != ','){
val += input[temp];
}
if(timekeeper == 0){
userID = val;
}
else if(timekeeper == 1){
timestamp = val;
}
else if(timekeeper == 2){
measurementID = val;
}
else if(timekeeper == 3){
value = (double)val;
}
timekeeper++;
}
These are the errors I am getting, if they are any help.
exp.c:87:7: error: invalid operands to binary + (have ‘char[1024]’ and ‘int’)
exp.c:90:6: error: incompatible types when assigning to type ‘char[1024]’ from type ‘char *’
exp.c:93:13: error: incompatible types when assigning to type ‘char[1024]’ from type ‘char *’
exp.c:96:8: error: incompatible types when assigning to type ‘char[1024]’ from type ‘char *’
exp.c:99:3: error: pointer value used where a floating point value was expected