Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.
hameedkhan
Havaldaar
Posts: 141 Joined: Wed Apr 07, 2004 12:58 am
Location: Karachi, Pakistan
Post
by hameedkhan » Mon May 03, 2004 5:43 pm
hi,
i just started programming in linux. i was trying to make the following programme but the programme didn't work as expected. i just want to know how can we print the character with ascii value 1 because the following programme isn't priniting the character with ascii value 1.
Code: Select all
#include <stdio.h>
main()
{
printf("Ascii=%d, Character=%c\n",1,1);
}
when i try to run the above programme i got the following output.
Code: Select all
hameed@khan:~/programming/letusc$ cc asciival1.c
hameed@khan:~/programming/letusc$ ./a.out
Ascii=1, Character=
hameed@khan:~/programming/letusc$
anybody know what can i do to print or we can't print those special character in linux
Thanks,
Hameed Khan.
jargon
Lieutenant Colonel
Posts: 691 Joined: Mon Oct 13, 2003 9:40 am
Post
by jargon » Mon May 03, 2004 8:36 pm
$: cat main.c
#include <stdio.h>
main()
{
printf("Ascii=%d,Character=%c\n",'1','1'); /* Note: Single-Quotes Around 1s */
return(0);
}
Last edited by
jargon on Tue May 04, 2004 5:26 am, edited 1 time in total.
jargon
lambda
Major General
Posts: 3452 Joined: Tue May 27, 2003 7:04 pm
Location: Lahore
Contact:
Post
by lambda » Mon May 03, 2004 9:15 pm
your code is correct. it is printing 1. type
jargon
Lieutenant Colonel
Posts: 691 Joined: Mon Oct 13, 2003 9:40 am
Post
by jargon » Tue May 04, 2004 5:24 am
The code is not correct , if he wants ascii values and character values he has to place his 1s in single quotes, which i corrected in his code,
jargon
hameedkhan
Havaldaar
Posts: 141 Joined: Wed Apr 07, 2004 12:58 am
Location: Karachi, Pakistan
Post
by hameedkhan » Tue May 04, 2004 8:26 pm
jargon wrote: The code is not correct , if he wants ascii values and character values he has to place his 1s in single quotes, which i corrected in his code,
i think you didn't understand my question. i want to print the character whose ascii value is 1. if i run the above programme in windows it will print a smiley face inplace of %c. i know in linux it will be little different.
i hope now you understand my question.
Thanks,
Hameed Khan
jargon
Lieutenant Colonel
Posts: 691 Joined: Mon Oct 13, 2003 9:40 am
Post
by jargon » Wed May 05, 2004 3:15 am
Ah, my mistake sorry..
Then look it up here,
Using what lamba said the octal value was 001,
thus what should have been printed out is SOH (Start of Heading)
http://rabbit.eng.miami.edu/info/ascii.html
Look under the invisibile characters section of page.
jargon
hameedkhan
Havaldaar
Posts: 141 Joined: Wed Apr 07, 2004 12:58 am
Location: Karachi, Pakistan
Post
by hameedkhan » Wed May 05, 2004 1:16 pm
Thanks lambda and jargon,
Thanks for your help
Hameed Khan