954,206 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

My program is skipping some statements.

I have no idea why.
The lines it's skipping is the system("PAUSE");.
Not the first two but the last two.

#include <stdlib.h>
#include <stdio.h>

int main()
{
      char Big, Small;
      Big='Z';
      Small='z';
      printf("Z=%d.\nz=%d.\n",Big,Small);
      system("PAUSE");
      int X,Y;
      X=72;
      Y=104;
      printf("74=%c.\n104=%c.\n",X,Y);
      system("PAUSE");
      double DblNum = 123.456;
      printf("f=%f.\nScientific=%e.\ntestF=%F.\n",DblNum,DblNum,DblNum);
      system("PAUSE");
      char Newline = '\n';
      printf("newline=%d.\n",Newline);
      system("PAUSE");
      return 0;
}
Jaav
Newbie Poster
12 posts since Jun 2007
Reputation Points: 10
Solved Threads: 1
 

worked ok for me on Vista using VC++ 2005 Express. If you are using *nix maybe it does not have a pause shell command ???

Ancient Dragon
Retired & Loving It
Team Colleague
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
 

I just tried it in VC++ express now too and it worked.
I used Dev-C++ before.
I guess i'm not going to be using Dev-C++ again.

Thanks.

Jaav
Newbie Poster
12 posts since Jun 2007
Reputation Points: 10
Solved Threads: 1
 

I got the same problem in another program I made using VC++ express now.

#include <stdlib.h>
#include <stdio.h>

int main()
{
	putchar(66);
	putc(121,stdout);
	putchar(101);
	putchar(10);
	system("PAUSE");

	int in = 123;
	int floa = 123.456;
	printf("%-3d\n%-6.3f\n",in,floa);
	system("PAUSE");
}


It ignores the last system("PAUSE"); but not the first one.
I need to know what causes these problems.
Dev-C++ wasn't the only compiler with this problem.

Jaav
Newbie Poster
12 posts since Jun 2007
Reputation Points: 10
Solved Threads: 1
 

Its not the compiler -- your program contains a bug line 13 -- change the data type to float and it will probably work as expected.

Ancient Dragon
Retired & Loving It
Team Colleague
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
 

Oh yea, sorry :$

Thanks

Jaav
Newbie Poster
12 posts since Jun 2007
Reputation Points: 10
Solved Threads: 1
 

Its always a good practice not to ignore warnings which appear when you compile your code. A warning about 'converting from float to int' would have given you the reason why your program is not working.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You