#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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Glenn PattonRank #6,159 · 275 reputationPosted Aug 21, 2012, 2:43 AM EDT
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!
VulpesRank #55 · 29.2K reputationPosted Aug 21, 2012, 5:02 AM EDT
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 PattonRank #6,159 · 275 reputationPosted Aug 21, 2012, 6:34 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 21, 2012, 7:24 AM EDT
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 PattonRank #6,159 · 275 reputationPosted Aug 21, 2012, 7:32 AM EDT