bhroask
bhroask

Reputation: 27

Visual Studio asking for a semicolon after for loop

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
   char ch;
   int count;

   while ((ch = getchar()) != '\n')
      for (count = 0, count <= (ch - '0'), count++)
         printf("%c", ch);

   return 0;
}

I haven't really gotten to the logistics of the coding. Just trying something. But as I was writing what seems like a simple for loop for the first time in C, I keep coming across an error on visual studio telling em to put a semicolon after the ) in the for loop statement. Well the problem is, even after I put one there, it keeps telling me I need a semicolon after the ).

I know that sometimes, the error might be somewhere else and it just tells you something totally irrelevant. I haven't even gotten to much coding yet and I can't find any really obvious mistakes.

I tried using brackets to block in the while and the for loops. If I remember correctly, I don't think you need a semicolon after the for statement...

Does anyone know what the problem might be? I thought maybe the project itself got a little faulty, so I opened a new project and wrote the new code in there. Sometimes, that works. I would just copy and paste the same exact code on a new project and it builds with no errors.

Upvotes: 0

Views: 380

Answers (2)

Ronaldo Nazarea
Ronaldo Nazarea

Reputation: 366

I believe it's asking you to put the semicolon after count <= (ch - '0'). Note that a for loop syntax is for (;;), where the each part can contain many expressions separated by commas.

Upvotes: 1

Steve
Steve

Reputation: 216293

A lot of time has passed from I last used C++ but your loop should be

for (count = 0; count <= (ch - '0'); count++)

Upvotes: 1

Related Questions