Printing a smiling face in C

Status
Not open for further replies.

mehulved

18 Till I Die............
I have been trying to solve this problem in C
"Write a program to fill the entire screen with a smiling face. The smiling face has an ASCII value one."
I did misunderstand the program and have made errors, but the program is here *rafb.net/p/oFCBvw86.html
Now, the main problem is:
I have given
char i;
printf(" %c", i);

Now on compiling and running this program in a terminal, I just get blank spaces no smiling face. I have no clue now, where is it going wrong.
 

shantanu

Technomancer
yeah it gives smiley now:

try this now:

#include <stdio.h>

int main()
{
int x,y;
char i=1;
for(x=1;x<=800;x++) //since there are 800 pixels on X axis, one char is 1 pixel i assume
{
printf(" %c ", i); //prints a smiley (you forgot to give a space after " %c " )
if(x==800)
printf("\n"); //gives a line break when 800 pixels are reached
y=x;
if(y==800)
break;

}
}
 
OP
M

mehulved

18 Till I Die............
Oops, looks like i put it up before updating it, i=1 not 48 in my file right now. OK i will try to add a space after %c and see how it goes.

Can I have a screenshot of what you got? Also, it seems I am missing it by a long way as the chapter covers for, while loops. And it just asks to print one smiling face. With what I am doing, it's missing one or the other.
 
Last edited:

shantanu

Technomancer
its printing many smiling faces... i think its some looping error..
here is the screen shot : *img481.imageshack.us/img481/2910/mehulse3.jpg

value of i is varying here... (wait) i am working on it... :p
 
Last edited:
OP
M

mehulved

18 Till I Die............
Well so it's seems to be like the smileys won't show on linux. I wonder if it's something windows specific.
 

shantanu

Technomancer
what value of I you gave... ?? and i dont think the libaries etc. would also be different in windows and linux :p
 
Last edited:
OP
M

mehulved

18 Till I Die............
I gave i=1
Later on I was just changing it around to other values cos some friend told me that it might be taking i as int 1. Even before this I made a program to print ASCII values and their equivalent characters, that time too, it just gave me blank output for many of those ASCII characters.
If not the libraries then could it be the compiler? Can someone try compiling this program on DevC++(I guess it has C compiler too) and see if it comes out right?
 

Garbage

God of Mistakes...
Try this....

Only change the values of x & y in loops according to screen size.
I wrote this program as my college assignment.
It is compiled using Bloodshed DevC++
Correct me if I'm wrong plz.

#include <stdio.h>
#include <conio.h>

int main()
{
int x,y;
int i=1;
for(y=1;y<=20;y++)
{
for (x=1;x<25;x++)
printf(" %c ", i); //prints a smiley
printf("\n"); //goes on next line
}
getch();
}
 

aditya.shevade

Console Junkie
tech_your_future said:
Well so it's seems to be like the smileys won't show on linux. I wonder if it's something windows specific.

I also think that it is OS specific. I have designed a tictactoe program, where I have printed the gameboard using ascii char. But they all get messed up in Linux.

Gotta run now, will post the O/P later.

Aditya

Hi,

You can try this code and see if 1 actually gets printed as a smiley.
Code:
main()
{
int i=0;

for(i=0;i<256;i++)
{
    printf("%d = %c\t",i,i);
}

getchar();

return 0;
}

As you would have guessed, it will print the number and corresponding ascii character. Then you will be able to see, which number prints the smiley.

I have had the same problem with my program as said above. Instead of printing the lines, the ascii characters are printed as ? and :. Maybe you need the change the default encoding style.

Will try and tell you.

Aditya
 
Last edited:
OP
M

mehulved

18 Till I Die............
aditya I have already made that program earlier and it gives me quite a lot of blank spaces. At first I had no clue why it's happening so, but now I think there's something that's either different or it's missing. I will try asking this on irc, maybe we'll come to know what's the reason it's happening.
 

casanova

The Frozen Nova
#include <stdio.h>

int main()
{
int x;
char i=1;
for(x=1;x<=28*80;x++) //since there are 80 columns and 24-30 rows and increment the counter with no. of chars within the quotes.
printf("%c", i);
}

This program is enough to run it. Sry, I dont run linux and updated the proggy as it was logically incorrect.

When in text mode it is 80 chars in a single row and somewhere around 24-30 columns.

*img353.imageshack.us/img353/8654/smileypm1.th.jpg
 
Last edited:

mediator

Technomancer
Yes, windows and linux libraries r different. Thats what zeeshan and I discussed in another thread!

Take a look at here => The Ascii Table!
Now u can clearly observe that 48 is the ascii value of 0. So u cannot print a smiley on 48.

Also u can witness that the characters whose ascii value ranges from 32-126 are readable characters consisting of alphabet, "+" ,commas,numbers(0-9) etc!

The ASCIIs out of this range r the ones which give funny characters!
Try this modified code! And u can create a "for loop" for the those non-readable ASCIIs to see what funny charcters they give!

#include <stdio.h>

int main()
{
int x,y;
int i=28;
for(x=1;x<=800;x++) //AFAIK, pixels on x axis depend on resolution!
{
printf(" %c ", i); //dont know about smiley but 48 is the ascii value of 0!
if(x==800)
printf("\n"); //gives a line break when 800 pixels are reached


y=x;
if(y==800)
break;
}


}
 
OP
M

mehulved

18 Till I Die............
Firstly, we are getting it wrong. That's the mistake even I made in the first place. The question clearly says that it's just 1 smiling face not so many.
And yeah in the question they've mentioned that ASCII value of 1 should be used, so the question is faulty by itself. The author at the beginning has intimated that he'd give a note if there were differences so I will try to mail him and see about this. By the way, this is from 'Let Us C' by 'Yashwant Kanetkar'.
 

mediator

Technomancer
Your question is no longer there in the link. Also, how can there be one smiling face when u have put up a loop of size 800? :confused:
 
OP
M

mehulved

18 Till I Die............
Read my first post again. The question is there on the second line.
And I have already said that I didn't read the question properly, I realised it while putting up this post.
But, I doubt if it will work anyways as it seems the ASCII value 1 doesn't print the smiling face on linux at all.
 

aditya.shevade

Console Junkie
^^ Ascii value of 1 prints nothing here. I am using OpenSuSE 10.2. Moreover, I checked all the values..... there is no smiling face anywhere.....

Aditya
 

mediator

Technomancer
Okies!
"Write a program to fill the entire screen with a smiling face. The smiling face has an ASCII value one."
If this is what u were asking then it sounds very illogical to me! On one hand its saying to fill the "entire screen with a smiling face" and then it says it has an ascii value 1 :confused: ?
U cannot AFAIK, print a small funny character on the entire screen!

OR, it cud be that the question hints at how the smiling face looks like with its ascii character?

I don't have much experience with these funny characters. But what I observed is that windows and linux (diff. OSs) may be having different funny characters for non-readable ASCII codes. And if u r practising Yashwant Kanetkar's C, then u shud practise it on "Turbo C 3". I dunno, but he may not be having experience with linux's c programming.

So if u r programming in C on Linux then I suggest u read some UNIX programming book or some book like GCC-The complete reference!
 

REY619

Ambassador of Buzz
Sorry for offtopic, but can someone give me the link to download that Turbo C++ IDE Compiler??
I searched but cant find...
Thanx.
 
OP
M

mehulved

18 Till I Die............
I doubt if yashwant kanetkar doesn't know C on Linux, cos the last 2 chapters are dedicated to C in the book. Maybe it's us who're missing the point here. There is a separate book for answers which can be bought but I am not keen on buying it at this point of time.
I will refer to gcc manual and stuff later on when I come to C programming under Linux.
And I am not interested in adding wine/dosbox so tc is out.
 
Status
Not open for further replies.
Top Bottom