I have seen some examples and tried to do something but now I am stuck.
The working code is
char quality[5][10];
char * qualities;
qualities = strtok (message, "\n");
int k = 0;
while (qualities != NULL){
if (k == 0) {
strcpy(quality[0], qualities);
}
else if ( k == 1) {
strcpy(quality[1], qualities);
}
else if ( k == 2) {
strcpy(quality[2], qualities);
}
else if ( k == 3) {
strcpy(quality[3], qualities);
}
else if ( k == 4) {
strcpy(quality[4], qualities);
}
qualities = strtok (NULL, "\n");
k++;
}
However this works with fixed length(in this case just 5), however I would like to assign a variable to quality variable but in that case while loop would not work. What should I do?
Replace this block
with these two lines:
This is an equivalent code, but it will work with any number of items, up to the number of elements in the
qualityarray.Since the number of elements is fixed, you should change
to
where
Nis the number of elements inqualities.