dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
May 6, 1997

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Program fails because do ... while loop needs braces

Question:
I'm a beginner in C programming. I have Microsoft Visual C++ 4.0.

I've read the book Programming with C by Byron Gottfried.

Unfortunately, no matter which simple program I try to write, I always run into a mistake. The error I make doesn't seem wrong, so I don't know what to change ...

I'd appreciate it if you could help me with this simple program and tell me what to change. I want to make it so that it inputs characters and stores them as other character ('a' as 'b', 'b' as 'c' .... etc.) The error is: (23) : error C2061: syntax error : identifier 'i'

This is the program:

#include 
#include 

main()
{
	FILE *fpt;
	int i;
	char c;
	
	/* open file enc.dat as write-only to store coded text */
	fpt=fopen("enc.dat", "w");

	/* send to ASCII and code */

	
	do
		c=getchar();
		i=c;
		++i;
		c=i;
		putc(c, fpt);
	while (c != '%');


	/* close the enc.dat */
	fclose(fpt);
}

Answer:
The problem is that you need braces around the body of your do ... while loop write the do ... while block as follows.

do
	{
		c=getchar();
		i=c;
		++i;
		c=i;
		putc(c, fpt);
	}
	while (c != '%');
and you will be OK.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date