The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



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

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 12-06-2008
tazan_007 tazan_007 is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 3
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
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0