12-13-2008
[U16511@maildev c_cpp]$ ./a.out
0123456789015
0012345678901ñ 15[U16511@maildev c_cpp]$ 5
It means nothing related to a string ending 12.
It is a memory managment issue.
Your question is "why'. I will try to answer.
In the input string there are 13 characters, but str is alloted for 12 characters. So where will keep the last ASCII character reading into ? Where will keep the charcter for string end '\0'.
So if you alllocate a location for 12, maximum you can read 11 characters. Since the 12 th charcter will be used by the '\0'.
Then next question why the wiered character is coming out through printf ? I think printf is trying to print a nonprintable charcter while searching for '\0' ; since in its format string, the first one is "%s". It means printf should print a string. By definition string should have a charcter '\0' at end . If it is not there we cannot assure what it wil print. The decision is not able to decide even by using Heisenberg's Uncertainity principle. So believe in Gods grace!!
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I used Notepad to compile my txt file and then I transferred this file to UNIX. When I use vi to open the file, I found that at the end of each line there was a "^M" character.
In the original txt file there was not this character. Why this character would been added automatically in UNIX? (4 Replies)
Discussion started by: Jasmine
4 Replies
2. UNIX for Dummies Questions & Answers
Hello every one and thanks in advance for the time you will take to think about my problem.
I would like to know if it's possible (in BASH) to read a text file character after character.
Exactly this is what I would like to do :
Txt file : ATGCAGTTCATTGCCAAA...... (~2.5 millions... (3 Replies)
Discussion started by: sluvah
3 Replies
3. Shell Programming and Scripting
Hi all,
I executed this script
top -n 1 | awk '{ if (NR==3) print $2 }'and it will give me in console
'31.6%us,'however, if I put the same script in txt file
top -n 1 | awk '{ if (NR==3) print $2 }' >> test.txtwhen I open the test.txt
I see
31.6%ESC(BESCI just actually need the 31.6 % to be... (1 Reply)
Discussion started by: peuceul
1 Replies
4. Shell Programming and Scripting
Hi friend,
i have the following problem:
when i am writting the below command on the command prompt , its working.
while read -n 1 ch; do echo "$ch" ; echo "$ch" ; done<file_name.out.
but when i am executing it after saving it in a ksh file, its not working.
Please helppppppppp .. thankss... (18 Replies)
Discussion started by: neelmani
18 Replies
5. Shell Programming and Scripting
I have written an application in Tcl-Expect which spawns minicom and
sends and receives data via the serial port. Sometimes i see that the
application receives control characters along with human readable data.
A search on the internet tells me that the control characters are
nothing but the VT... (0 Replies)
Discussion started by: cityprince143
0 Replies
6. Shell Programming and Scripting
Hi All,
I am trying to read a file character by character,
#!/bin/bash
while read -n1 char; do
echo -e "$char\c"
done < /home/shak/testprogram/words
Newyork is a very good city.
Newyorkisaverygoodcityforliving
I need to preserve the spaces as thats an... (3 Replies)
Discussion started by: Kingcobra
3 Replies
7. Shell Programming and Scripting
Hi,
I am trying to sort a csv file which has say 10 lines each line having a row size that is upto 30183 no. of COLUMNS (Row length = 30183). There is a LINE FEED (LF) at the end of each line. When I try to sort this file say, based on the second FIELD using the below command,
sort -t ',' +1... (5 Replies)
Discussion started by: DHeisenberg
5 Replies
8. Shell Programming and Scripting
so, i want to tail about the last 3000 lines of a log file and find the column that has the same number of characters across all 3000 lines (or most of the 3000 lines)
tail -3000 logfile | while read line
do
ColumnCharCount=$(for eachwordorwhatever in "${echo $line}"
do
... (8 Replies)
Discussion started by: SkySmart
8 Replies
9. Shell Programming and Scripting
Good day, I am a newbie here and thanks for accepting me
I have a task to modify input data where my input data looks like
123|34567|CHINE
1|23|INDIA
34512|21|USA
104|901|INDIASee that my input has two columns with different character length but max length is 5 and minimum length is 0 which... (1 Reply)
Discussion started by: fastlearner
1 Replies
10. What is on Your Mind?
Today I changed the forum mysql database to permit 2 letter searches:
ft_min_word_len=2
I rebuilt the mysql search indexes as well.
Then, I added a "quick search bar" at the top of each page.
I have tested this and two letter searches are working; but it's not perfect,... (1 Reply)
Discussion started by: Neo
1 Replies