![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| print a file with one column having fixed character length | smriti_shridhar | Shell Programming and Scripting | 2 | 10-03-2008 09:02 AM |
| Using Awk script to check length of a character | amit1_x | Shell Programming and Scripting | 2 | 07-02-2008 10:10 AM |
| extran NUll character added after end of line "\n" | arunkumar_mca | UNIX for Dummies Questions & Answers | 1 | 11-12-2007 01:23 PM |
| reading a single character in C | alodha | High Level Programming | 3 | 01-28-2005 06:22 AM |
| there was a strange character(^M) been added automatically in UNIX | Jasmine | UNIX for Dummies Questions & Answers | 4 | 11-30-2001 03:12 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Strange character added when reading to buffer with length of 12
Hi all,
I got trouble with reading and writing ( to standard input/output, file, socket whatever...). I will briefly describe it by giving this example. I want to read a long string from keyboard but i don't know how long it is b4. So i need to know the number of character i will read first. Then i initialize my buffer to fit my desirable string and read this string from standard input. However, everything is ok until i try to read 12 characters from keyboard. A weird character is automatically added : "ñ". And when i check the string length, it is 15. I don't know why because with other cases, there isn't some things like this happened. Just a sample code: #include <stdio.h> #include <fcntl.h> #include <stdlib.h> #include <string.h> main(){ int fd; char *str; int a; char enter[1]; scanf("%d",&a); str = malloc(a*sizeof(char)); read(0,str,a); printf("%s ----- %d",str,strlen(str)); } I have searched but still found nothing related to this. Thanks |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|