02-08-2007
Help with easy project - reading a file.
I need to do a project that is suppose to read a file and it is suppose to display the number of the line plus whatever the file is reading indented by a tab:
example file:
"This is
the test
file."
expected output:
1 "This is
2 the test
3 file."
I am having two problems.
1. I need to check first if the file is empty.
2. The program includes the last line in the file, even though its empty. It comes out like this:
1 "This is
2 the test
3 file."
4
This is my program:
#include <stdio.h>
main()
{
int c, nl_cnt = 1;
if ((c = getchar()) == 'null') /*<-----"Doesn't work */
printf("File is empty\n");
else
{
printf("%d\t", nl_cnt);
while ((c = getchar()) != EOF)
if (c == '\n')
{
++nl_cnt;
printf("\t\n");
printf("%d\t", nl_cnt);
}
else
printf("%c", c);
}
}
I need help please!
2 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi again. Sorry if it seems like I'm spamming the boards a bit, but I figured I might as well ask all the questions I need answers to at once, and hopefully at least get some.
I have installed Solaris 10 on a server. The default text editors are there (vi, ex, ed, maybe others, I know emacs is... (4 Replies)
Discussion started by: EugeneG
4 Replies
2. Solaris
i have two doubts..
1. what is the use /etc/project file. i renamed this file and when i tried to switch user or login with some user account the login was happening slowly. but when i renamed it to original name it was working fine... why so?
2. unix already has useradd and grouadd for... (4 Replies)
Discussion started by: chidori
4 Replies
LEARN ABOUT DEBIAN
lnptest2
lnptest2(1) General Commands Manual lnptest2(1)
NAME
lnptest2 - LNP Client Test Application #2 (shorter test)
SYNOPSIS
lnptest2
DESCRIPTION
lnptest2 is an LNP Daemon test client used to test the connection between a client LNP program (in this case lnptest2) and the LNP daemon
through the Ir Tower to a corresponding test program running in an RCX. See the FILES section for the location of the RCX test program
source code (distributed with this package).
OPTIONS
lnptest2 does not support command-line options.
USAGE
To run the test:
- compile the lnptest2.c RCX program
- start the lnpd daemon
- download the lnptest2.lx program to the RCX
- at the RCX, run the program just downloaded to the RCX
- run this lnptest2 program
- inspect the output looking for lack of failure messages
FILES
/usr/share/doc/lnpd/examples/rcx
In this directory is the source to the RCX-side program which is called lnptest2.c but written to be compiled against BrickOS.
SEE ALSO
lnptest(1), lnpdll(1), lnpd(8)
You can find additional documentation in /usr/share/doc/lnpd (on Debian GNU/Linux systems)
AUTHOR
lnptest2 was written by Michael Obenland <mobenland@users.sourceforge.net> This man page was written by Stephen M Moraco
<stephen@debian.org>
January 23, 2005 lnptest2(1)