GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Feb-2005, 15:45
scramble scramble is offline
Awaiting Email Confirmation
 
Join Date: Feb 2005
Location: Virginia
Posts: 4
scramble is on a distinguished road

My programs output is a string of smiley faces


I am obviously a beginning programmer. I have a C program that takes input that is redirected from a file, strips out all vowels, and prints the rest to the screen. When I run it, it prints out a long string of smiley faces instead of the text. The redirected file is a simple text file created with notepad that contains some text.
Any suggestions?
Attached Files
File Type: txt isvowel.txt (552 Bytes, 37 views)
  #2  
Old 27-Feb-2005, 16:53
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,243
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by scramble
I am obviously a beginning programmer. I have a C program that takes input that is redirected from a file, strips out all vowels, and prints the rest to the screen. When I run it, it prints out a long string of smiley faces instead of the text. The redirected file is a simple text file created with notepad that contains some text.
Any suggestions?
Sure.
1) Make sure you aren't outputting a string using "%c" in the printf() statement. Conversely make sure you aren't trying to output a character with "%s".
2) Be sure you aren't trying to output characters beyond the limit of your string

Also, post code sections here. Many of us won't download files -- we have enough stuff on our harddrives...
__________________

Age is unimportant -- except in cheese
  #3  
Old 27-Feb-2005, 18:10
scramble scramble is offline
Awaiting Email Confirmation
 
Join Date: Feb 2005
Location: Virginia
Posts: 4
scramble is on a distinguished road
I didn't paste the source inline in my message because the forum doesn't display some of it correctly. I just read the post on how to enclose source code. Here it is:

CPP / C++ / C Code:
#include <stdio.h>

int isvowel(char c);

int main(void)
{
	char c;
	printf("\n%s\n%s\n%s\n\n",
		"This program takes standard input redirected",
		"	from a text file, and prints it to the",
		"	screen minus all vowels.");
	while(c = getchar() != EOF){
		if(isvowel(c) == 1) {
			continue;
		}
		else putchar(c);
	}
	return 0;
}

	int isvowel(char c)
	{
		if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='y')
			return 1;
		if(c=='A' || c=='E' || c=='I' || c=='O' || c=='U' || c=='Y')
			return 1;
		else return 0;
	}
  #4  
Old 27-Feb-2005, 19:22
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,693
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by scramble
Here it is:


Try printing out the characters in hex. Maybe you can figure how the values are equal to 0x01. Hint: precedence of = and !=

That is, instead of this:

CPP / C++ / C Code:
else putchar(c);

Try this:

CPP / C++ / C Code:
    else printf("%c: %02x ", c, c);

Regards,

Dave
  #5  
Old 27-Feb-2005, 20:25
scramble scramble is offline
Awaiting Email Confirmation
 
Join Date: Feb 2005
Location: Virginia
Posts: 4
scramble is on a distinguished road
I changed my code as you suggested, and here is the output:

☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺:
01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 0
1 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01
☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺: 01 ☺:

I still don't understand what is going wrong. Thank you for your your help.
Scramble
  #6  
Old 27-Feb-2005, 20:36
scramble scramble is offline
Awaiting Email Confirmation
 
Join Date: Feb 2005
Location: Virginia
Posts: 4
scramble is on a distinguished road
I figured it out!
I changed this:
CPP / C++ / C Code:
while(c = getchar() != EOF){
to this:
CPP / C++ / C Code:
while((c = getchar()) != EOF){

Thanks,
Scramble
  #7  
Old 27-Feb-2005, 23:51
machinated machinated is offline
Regular Member
 
Join Date: Mar 2004
Location: victoria, canada
Posts: 324
machinated has a spectacular aura aboutmachinated has a spectacular aura about
yeah the compiler is laughing at you. Don't be discouraged, it does that to all the beginners

Quote:
Originally Posted by scramble
I am obviously a beginning programmer. I have a C program that takes input that is redirected from a file, strips out all vowels, and prints the rest to the screen. When I run it, it prints out a long string of smiley faces instead of the text. The redirected file is a simple text file created with notepad that contains some text.
Any suggestions?
__________________
spasms!!!
 
 

Recent GIDBlogFlickr uploads of IA pictures by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Read a .html file, check that file for links salemite C Programming Language 10 17-Jan-2008 07:56
Re: Conversion: Binary, Decimal, Hexadecimal WaltP C Programming Language 1 10-May-2006 06:49
No output from loop function crystalattice C++ Forum 2 20-Dec-2004 20:39
using vector or array oshiotse C++ Forum 4 16-Apr-2004 10:59

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:36.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.