this program is to double space the lines but it works perfectly but there is two "unusfull lines in my point of view since i tried every possible version to see if the any porblem will hapen if omited but there was none...could we just take them out?"
this is the code: -
-
#include <stdio.h>
-
#include <string.h>
-
-
#define LINE_LEN 80
-
#define NAME_LEN 40
-
-
int main(void)
-
{
-
char line[LINE_LEN], inname[NAME_LEN], outname[NAME_LEN];
-
FILE *inp,
-
*outp;
-
char *status;
-
int i = 0;
-
-
printf("Name of the input file -> ");
-
scanf(" %s", inname);
-
printf("Name of the output file -> ");
-
scanf(" %s", outname);
-
-
inp = fopen("inname.txt", "r");
-
outp = fopen("outname.txt", "w");
-
-
for(status = fgets(line, LINE_LEN, inp);
-
status != 0;
-
status = fgets(line, LINE_LEN, inp))
-
{
-
if(line[strlen(line) - 1] == '\n') //these are two lines.
-
line[strlen(line) - 1] = '\0'; //these are two lines.
-
fprintf(outp, "%3d>> %s\n\n", ++i, line);
-
}
-
return (0);
-
}
-
thx!
5 1425
this program is to double space the lines but it works perfectly but there is two "unusfull lines in my point of view since i tried every possible version to see if the any porblem will hapen if omited but there was none...could we just take them out?"
this is the code: -
-
#include <stdio.h>
-
#include <string.h>
-
-
#define LINE_LEN 80
-
#define NAME_LEN 40
-
-
int main(void)
-
{
-
char line[LINE_LEN], inname[NAME_LEN], outname[NAME_LEN];
-
FILE *inp,
-
*outp;
-
char *status;
-
int i = 0;
-
-
printf("Name of the input file -> ");
-
scanf(" %s", inname);
-
printf("Name of the output file -> ");
-
scanf(" %s", outname);
-
-
inp = fopen("inname.txt", "r");
-
outp = fopen("outname.txt", "w");
-
-
for(status = fgets(line, LINE_LEN, inp);
-
status != 0;
-
status = fgets(line, LINE_LEN, inp))
-
{
-
if(line[strlen(line) - 1] == '\n') //these are two lines.
-
line[strlen(line) - 1] = '\0'; //these are two lines.
-
fprintf(outp, "%3d>> %s\n\n", ++i, line);
-
}
-
return (0);
-
}
-
thx!
No, they're not necessary. From cplusplus.com:
char * fgets ( char * str, int num, FILE * stream );
Get string from stream
Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or a the End-of-File is reached, whichever comes first.
A newline character makes fgets stop reading, but it is considered a valid character and therefore it is included in the string copied to str. A null character is automatically appended in str after the characters read to signal the end of the C string.
Iknow all that but whene I'v omited theme it just work as well???
and if we don't take the two lines out if new line character reached it will be \0\0 at the end of the str am I righbt?
and that also is a waste of cells??
The fgets() function appends the \n character in the buffer before terminating it
with a \0 character, so either leave those lines in and print two \n yourself or
remove them and print just one \n character if you want doubly spaced lines.
kind regards,
Jos
that is an answer !!! thank you!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Anon |
last post by:
Hello all,
I'm hoping for some guidance here... I am a c/c++ "expert", but a
complete python virgin. I'm trying to create a program that loads in the
entire FreeDB database (excluding the...
|
by: J. Campbell |
last post by:
From reading this forum, it is my understanding that C++ doesn't
require the compiler to keep code that does not manifest itself in any
way to the user. For example, in the following:
{
for(int...
|
by: Geronimo W. Christ Esq |
last post by:
Are there any scripts or tools out there that could look recursively
through a group of C/C++ source files, and allow unreferenced function
calls or values to be easily identified ?
LXR is handy...
|
by: Nick Gilbert |
last post by:
Hi,
I have to send an array of prices for a list of products over XML.
Currently my XML data looks like this:
<ArrayOfProd>
<Prod Code="productcode001">
<Prices>
<P F="2005-01-01"...
|
by: Jack |
last post by:
I have a chunk of code that loads a few dozen function pointers into
global variables. I'm concerned with unused memory consumption. What
if the client only needs to use one or two functions? Then...
|
by: Cleverbum |
last post by:
I'm not really accustomed to string manipulation and so I was wondering
if any of you could be any help i speeding up this script intended to
change the format of some saved log information into a...
|
by: schwehr |
last post by:
Hi All,
I've got a small logging class that I would like to have a way to
optimize away as much as possible with the minimum of macro trickery.
I've got working code, but not having done C++...
|
by: Pavan |
last post by:
Hi, I want to know if there is any software for measuring lines of
code of my c++ application.
I found out a tool, sloccount, but it gives only physical lines of
code.
I found out one more...
|
by: George2 |
last post by:
Hello everyone,
Should I delete memory pointed by pointer a if there is bad_alloc when
allocating memory in memory pointed by pointer b? I am not sure
whether there will be memory leak if I do...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |