473,785 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

About (char)13 & (char)10

What char represent "a new line"?13 or 10, or both?
I got a lot of problem when read a char. Eg.
========
1 2
a b

========
If I write:
int n1,n2;
char c1,c2;
scanf("%d%d",&n 1,&n2);
scanf("%c%c",&c 1,&c2);

I got:
c1=10('\n')
c2=97('a')

So I must wrote:
int n1,n2;
char c1,c2;
scanf("%d%d",&n 1,&n2);
scanf("%c",c1);
scanf("%c%c",&c 1,&c2);
But I don't know if the char of new line in linux is also 10, or 10&13.
If I need to read some more complex vars & chars, how can I solve this
problem?

Nov 15 '05
13 36232
On 11 Nov 2005 04:06:13 -0800, in comp.lang.c , "Betaver"
<Be*****@gmail. com> wrote:
What char represent "a new line"?13 or 10, or both?
Neither.

From C's perspective, \n is a newline, and \r is a carriage return.

I got a lot of problem when read a char. Eg.
scanf("%d%d",& n1,&n2);


Don't use scanf.

Its hard to use (as you have found), and dangerous. It doesn't consume
newlines, has poor error checking, and so forth.

See section 12.18, 12.20 and indeed anything from 12.12 in the FAQ.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #11
On 11 Nov 2005 05:51:20 -0800, in comp.lang.c , "Betaver"
<Be*****@gmail. com> wrote:
Er, too hard to me. Too special C and system works.
If you open a file in text mode, your OS may translate some
characters.
If you open it in binary mode, it may not.

For instance Windows typically uses two characters for a newline. When
reading it into a text editor, the two get converted into a single
'\n'. However when reading it into a hex editor, they don't.
So can I only use one scanf("%c") for each newline and it works well
both in Linux & Windows?


If the file is opened in text mode. But please don't use scanf.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #12
On 11 Nov 2005 05:32:49 -0800, in comp.lang.c , "Betaver"
<Be*****@gmail. com> wrote:
To Emmanuel:
But why my 8bytes file windows shows 10bytes?


Because thats how your OS shows the file to different applications (in
this case, "ls" and your own programme).

On OpenVMS it would have a disk size of 512 bytes, but still only be
eight bytes of data.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #13
Thanks for your help!

Nov 15 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2753
by: Alex Vinokur | last post by:
========================================== Windows 2000 Professional CYGWIN_NT-5.0 1.5.4(0.94/3/2) GNU g++ version 3.2 20020927 (prerelease) GNU objdump 2.14.90 20030901 ========================================== We can see that the same assembly code is generated for * foo2 (char& )
1
1761
by: oembuilders | last post by:
Hi all, Would anyone know a way to convert a char(10) in format 'm/d/yyyy' to 'mm/dd/yyyy', so I can convert the column to datetime format. Thanks
1
3981
by: st | last post by:
Hi, I'm using xmlDocument.Save(xmlTextWriter) to create an Excel-readable file. All works well, except where I've replaced the carriage return chars in the .innertext to XML-compliant " "; It gets changed to "&amp;#10" and doesn't render new lines in the Excel sheet. Can anyone help? Many thanks,
13
2125
by: chellappa | last post by:
hi , please explain me , char pointer , char Array, char ,string... i have some many confussion about this... please clarify to me.. i need some example about this program by chellappa.ns
4
2292
by: jceddy | last post by:
Hey, I'm trying to write a file with unix-style newlines (ASCII character 10) from a c++ program on Windows...it seems that the most straightforward way to do that is just to print ( char )10, but it seems that when I try to print that to the file, the program still prints the full CR+LF Windows-style ending. The code I have looks something like this: param_file<<"BSEARCH_ALG SIMPLE"<<( char )10; Is there any way to keep the program...
21
2307
by: Wisdo | last post by:
Hi All, char to char ** is compile error. why? if i hava a string array. yes. it's not safe and it's better to use vector<stringinstead. but my point is the language feature. char sex = {"Male", "Female" };
2
10532
by: Enrico Sabbadin | last post by:
Hi, A few days go I fiund iut that the xmlserializer strips away /r/n out during deserialization (and just leave /n) ... I found out that you can resolve this problem using the deserialize overlaod that takes an xmltextreader instead of a stream .. However when it's time to Web Services you have no such a control over the deserialization phase AND I found out that WS strips out /r/n (an leave /n) ... I understand there are some XMl...
2
2525
by: medaps | last post by:
Hi, How do I save multi lines to a mysql memo field replacing char 13 char 10 to '\r\n' instead ?. Example the memo is saved as 'string1<13><10>string2' instead of 'string1\r\nstring2' The reason behind is to populate the mysql memo field to a html form field using a php module called from html as this: <? $s=trim($wg); echo "<script language='javascript'>window.parent.document.all.innerText=".$s.";</script>";
2
7042
by: iritchie | last post by:
*(Apologies, I posted this in the SQL Server forum first) Hello all, I am trying to write a query which breaks down a single address field into individual fields, with char(10) or a carriage return as the delimiter. "empltable" is the table I am using, and "address" is the field I am looking to split. So far I have managed to:
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10330
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9952
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.