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? 13 36228
A text file:
========
5
AAAAA
========
is 10bytes.(Maybe every newline is 2 bytes)
But scanf("%c") can only read 8 chars.
Can it read any newline as a '\n' no matter it is 10 or 10&13?
My header file is Gcc 3.4.2 provided.
Betaver wrote: A text file: ======== 5 AAAAA
======== is 10bytes.(Maybe every newline is 2 bytes)
Maybe {'5', '\n', 'A', 'A', 'A', 'A', 'A','\n', '\n' , '\n'}
But scanf("%c") can only read 8 chars. Can it read any newline as a '\n' no matter it is 10 or 10&13? My header file is Gcc 3.4.2 provided.
/* BEGIN type_.c */
/*
** This is a demonstration of a way to use fscanf on text files.
** It is not supposed to be an efficient implementation
** of the "type" command.
*/
#include <stdio.h>
#define ARGV_0 type_
#define LINE_LEN 250
#define str(s) # s
#define xstr(s) str(s)
int main(int argc, char *argv[])
{
int rc;
FILE *fd;
char line[LINE_LEN + 1];
if (argc > 1) {
while (*++argv != NULL) {
fd = fopen(*argv, "r");
if (fd != NULL) {
do {
rc = fscanf(fd,
"%" xstr(LINE_LEN) "[^\n]%*[^\n]", line);
if (!feof(fd)) {
getc(fd);
}
if (rc == 0) {
*line = '\0';
}
if (rc != EOF) {
puts(line);
}
} while (rc == 1 || rc == 0);
fclose(fd);
} else {
fprintf(stderr,
"\nfopen() problem with \"%s\"\n", *argv);
break;
}
}
} else {
puts(
"Usage:\n>" xstr(ARGV_0)
" <FILE_0.txt> <FILE_1.txt> <FILE_2.txt> ...\n"
);
}
return 0;
}
/* END type_.c */
--
pete
Betaver a écrit : What char represent "a new line"?13 or 10, or both?
In a text file context, the new line
character (actually 'end of line) is '\n'.
I got a lot of problem when read a char. Eg. ======== 1 2 a b
Use fgets() and your problems are gone.
--
A+
Emmanuel Delahaye
If I write a text file:
========
5
AAAAA
========
Windows says it's 10bytes. But scanf("%c") can only read 8 chars.
I think scanf read a 10&13 as a 10('\n'), but can scanf read all 10 or
10&13 as a 10?
To Emmanuel:
But why my 8bytes file windows shows 10bytes?
To pete:
I can sure no such newline at end of file.
I think I may use Hex Editor open it and find the 2 more chars.
Betaver wrote: To pete: I can sure no such newline at end of file. I think I may use Hex Editor open it and find the 2 more chars.
Your hex editor may see text files differently
from the way that a C program sees them.
--
pete
Er, too hard to me. Too special C and system works.
So can I only use one scanf("%c") for each newline and it works well
both in Linux & Windows?
Betaver wrote: What char represent "a new line"?13 or 10, or both?
In C, '\n' represents a newline.
Whether '\n' is represented by 13 (CR in ASCII) or 10 (LF in ASCII) or
both or by some other value or values depends on your OS and platform.
In any case, it should generally be irrelevant. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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& )
|
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
|
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
"&#10" and doesn't render new lines in the Excel sheet.
Can anyone help?
Many thanks,
|
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
|
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...
| |
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" };
|
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...
|
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>";
|
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:
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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,...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |