#include
char s[80];
int i, j,n;
int main() {
printf("Type in a word: ");
scanf("%s",s);
printf("Type in a number: ");
scanf("%d",&n);
i = 0;
j = strlen -1;
while (i < j) {
printf("%c",s[i]);
i = i + n;
}
}
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Glenn PattonPosted Aug 21, 2012, 11:32 AM
VulpesPosted Aug 21, 2012, 11:24 AM
The idea seems to be to print the first character of the input string, the (1 + n)th character, the (1 + 2n)th character and so on until the penultimate character of the string is reached.
So, if you entered 'glenn' and 2, the program would print 'ge' to the console. That's because 'j' would be 4 and so 'i' would go from 0 to 2 before the while loop ended.
Possibly, the loop should continue until the final character of the string is reached - in which case j should be set to strlen(s). We just don't know as we haven't seen the original question.
Glenn PattonPosted Aug 21, 2012, 10:34 AM
VulpesPosted Aug 21, 2012, 9:02 AM
You need to include string.h to use the strlen function and the latter needs to have an argument passed to it. The following compiles and runs fine:
Glenn PattonPosted Aug 21, 2012, 6:43 AM
Glenn
Got board at lunch had another look also you are trying to use string length with out the header included (string.h) and the string length is wrong have a look at using strlen correctly!