first linux programme

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.
Post Reply
hameedkhan
Havaldaar
Posts: 141
Joined: Wed Apr 07, 2004 12:58 am
Location: Karachi, Pakistan

first linux programme

Post by hameedkhan »

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 »

$: 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:

Re: first linux programme

Post by lambda »

your code is correct. it is printing 1. type

Code: Select all

./a.out | od -c
jargon
Lieutenant Colonel
Posts: 691
Joined: Mon Oct 13, 2003 9:40 am

Post by jargon »

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 »

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 »

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 »

Thanks lambda and jargon,
Thanks for your help

Hameed Khan
Post Reply