I'm currently learning how to program in C. As extra practice I was given some problems from my teacher. Here is what my problem is, I have to use this in my program:
void strSplitTokens (char *s1, char s2[][], int *numWords);
here is the rest of the problem: A call to strSplitTokens breaks string s1 into its words, it then saves each word in a distinct char array, and all the strings are saved in a single array of characters. Also, it saves the number of words using pointers in numWords. print the strings in the main with the following:
For(i=0;i<numWords;i++) printf("%s\n",s2[i]);
If I run it and give it a sentence like I like programming I need it to output:
I
Like
Programming
My main issue is that I was told not to use string.h, I am kind of lost on how to do it without it. Any advice and guidance would is greatly appreciated.
What I have so far is mostly mock up code which makes no sense:
#include <stdio.h>
void strSplitTokens (char *s1, char s2[][], int *numWords);
int main()
{
printf("Enter a sentence: ");
strSplitTokens();
For(i=0;i<numWords;i++)
{
printf("%s\n",s2[i]);
}
return 0;
}
void strSplitTokens (char *s1, char s2[][], int *numWords);
{
char s1;
scanf("%s",&s1);
if( s1 != '\n')
{
strSplitTokens();
}
}
Check character by character. Put the each character in the two dimensional array until space comes.
i=0;j=0;k=0;
while(s[k]!='\n') {
if(s[k]!=' ')
{
s1[i][j]=s[k];
k++;
j++;
}
else{
j=0;i++;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.