- This topic has 0 replies, 1 voice, and was last updated 3 years, 11 months ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
aiannum.com has rebranded as Progaiz.com
› Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 2: [Arrays] – Functions, Variable and Scope, Debugging, Arrays, and Command Line Arguments › Correct format for printf(“total words %i\n”, wordcounter + 1);
Tagged: arrays, c, initialise, readability problem
[dm_code_snippet background=”yes” background-mobile=”no” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
#include
#include
#include
int main(void)
{
string enterword = get_string("input: ");
int t = strlen(enterword);
printf("%i\n", t);
int counter = 0;
for(int i = 0; i<= t; i++)
{
if (enterword[i] == '.'|| enterword[i] == '!' || enterword[i] == '?'){
counter = counter + 1;}
}
printf("number of lines %i\n",counter);
int wordcounter = 0;
for (int i = 0; i<= t; i++)
{
if (enterword[i] == ' ' ){
wordcounter = wordcounter + 1;
}
}
printf("total words %i\n", wordcounter + 1);
}
[/dm_code_snippet]
My query for this thread is how do I have wordcounter = wordcounter + 1 correctly formatted.
Reply
https://edstem.org/us/courses/176/discussion/976720?comment=2211477[learn_press_profile]
