Program fails because do … while loop needs braces

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);}

The problem is that you need braces around the body of your do … while loopwrite the do … while block as follows.

do	{		c=getchar();		i=c;		++i;		c=i;		putc(c, fpt);	}	while (c != ‘%’);
and you will be OK.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

technology leadership

Why the World Needs More Technology Leadership

As a fact, technology has touched every single aspect of our lives. And there are some technology giants in today’s world which have been frequently opined to have a strong influence on recent overall technological influence. Moreover, those tech giants have popular technology leaders leading the companies toward achieving greatness.

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job