What I want to do is: The user inputs a string with commas; for example: 123456,44,55,,66
and I want to separate it and store in a new array without the commas; for example:
m[0][]={123456}, m[1][]={44}, m[2][]={55}, m[3][]={}, m[4][]={66}
123456
is the student ID number, 44
is the mark for 1st module, 55
is the mark for 2nd module, NULL
means that the student didn't take that 3rd module, and 66
is the mark for 4th module.
How can I exactly do that? What I know is that by detecting double commas, it means the student didn't take that 3rd module.
Here is what I have written so far:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void copystring(char m[],char temp[]);
main()
{
char temp[10000];
char m[10000][10000];
gets(temp);
copystring(m,temp);
printf("%s\n",m);
return 0;
}
void copystring(char m[],char temp[])
{
int i;
int j;
for (j=0;j<(strlen(temp));j++)
{
for (i=0;i<(strlen(temp));i++)
{
if (temp[i]!=*(",")&&temp[i]!=*(" "))
{
m[j][i]=temp[i];
}
}
}
}