The following is an example of input:
1 Les
L 01/02/04 2300 06:00AM SW Nashville
R 01/06/04 2400 10:00PM SW Kansas City
L 01/15/04 2440 10:00AM NW Minneapolis
R 01/15/04 3440 05:00PM NW Kansas City
2 Jen
L 01/02/04 2300 0600AM SW Nashville
R 01/06/04 2400 10:00PM SW Kansas City
Each employee #, Name can have 0 to many associated flights.
How can I build a C program to use scanf to collect the data
as input and output it to a text file? I need to be able to
display prompts using printf but I don't want the prompts
to appear in my text file.
Any help greatly appreciated.
Les 8 14548
"Les Coover" <lc******@cox.net.spam> wrote in
news:KLqub.10942$n23.8081@okepread02: How can I build a C program to use scanf to collect the data as input and output it to a text file? I need to be able to display prompts using printf but I don't want the prompts to appear in my text file.
Look up fprintf(), then fprintf() to stdout those prompts and fprintf() to
your text file the responses once scanned in.
--
- Mark ->
--
Mark
Does this look right? What do I declare fid as?
/* jeto.c */
#include <stdio.h>
#include <string.h>
int main(void)
{
fid = fopen('jeto.txt','w');
char store[100];
while (scanf("%99s", store)== 1)
{
printf("Enter");
fprint(fid, '%99s');
}
fclose(fid)
return 0;
}
"Mark A. Odell" <no****@embeddedfw.com> wrote in message
news:Xn********************************@130.133.1. 4... "Les Coover" <lc******@cox.net.spam> wrote in news:KLqub.10942$n23.8081@okepread02:
How can I build a C program to use scanf to collect the data as input and output it to a text file? I need to be able to display prompts using printf but I don't want the prompts to appear in my text file.
Look up fprintf(), then fprintf() to stdout those prompts and fprintf() to your text file the responses once scanned in.
-- - Mark -> --
In <1Srub.10948$n23.10939@okepread02> "Les Coover" <lc******@cox.net.spam> writes: Does this look right?
Nope.
What do I declare fid as?
What does your C book say?
/* jeto.c */
#include <stdio.h> #include <string.h>
What for?
int main(void) { fid = fopen('jeto.txt','w'); char store[100];
while (scanf("%99s", store)== 1) { printf("Enter"); fprint(fid, '%99s'); } fclose(fid) return 0; }
Before worrying about file I/O, you should *really* understand the
difference between string literals and character constants. It's one
of the most basic things of the language and nothing is going to work
until you have a clear idea which is which and where you have to use one
or the other.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
"Thomas Matthews" <Th**********************@sbcglobal.net> wrote in message
news:m6******************@newssvr32.news.prodigy.c om... Les Coover wrote: Mark
Does this look right? What do I declare fid as?
/* jeto.c */
#include <stdio.h> #include <string.h>
int main(void) { fid = fopen('jeto.txt','w'); char store[100];
while (scanf("%99s", store)== 1) { printf("Enter"); fprint(fid, '%99s'); } fclose(fid) return 0; } 1. Don't top-post, replies are appended to the bottom like this one or interspersed. 2. Look up streams in your text book or reference manual, especially "FILE". 3. See the C FAQ below.
-- Thomas Matthews
C++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txt C++ Faq: http://www.parashift.com/c++-faq-lite C Faq: http://www.eskimo.com/~scs/c-faq/top.html alt.comp.lang.learn.c-c++ faq: http://www.raos.demon.uk/acllc-c++/faq.html Other sites: http://www.josuttis.com -- C++ STL Library book
I have read your references, other references and the text book and still
cannot get this.
Could you give me another clue.
Following code still has a problem
/* jeto.c */
#include <stdio.h>
#include <string.h>
int main(void)
{
FILE *file; /* FILE pointer */
int em_no;
char store[100];
/* create a file for writing */
file = fopen ("jeto.txt", "w");
while(scanf ("%d %99s", &em_no, store)== 2)
{
printf("Enter, Example: 01 Les L 01/02/04 ",
"2300 06:00AM SW Nashville R 01/06/04 ",
"2400 10:00PM SW Kansas City");
fprint(file, "%d %50s\n", &em_no, store);
}
fclose(file); /* now close the file */
return 0;
}
Les
"Les Coover" <lc******@cox.net.spam> wrote: Could you give me another clue. Following code still has a problem
/* jeto.c */
#include <stdio.h> #include <string.h>
You don't use anything declared in string.h.
int main(void) { FILE *file; /* FILE pointer */ int em_no; char store[100]; /* create a file for writing */ file = fopen ("jeto.txt", "w");
Check 'file' here to make sure fopen succeeded.
while(scanf ("%d %99s", &em_no, store)== 2) { printf("Enter, Example: 01 Les L 01/02/04 ", "2300 06:00AM SW Nashville R 01/06/04 ", "2400 10:00PM SW Kansas City");
Wrong number of arguments. Look up printf in your C library
reference.
fprint(file, "%d %50s\n", &em_no, store);
There is no function fprint. Look up fprintf in your C library
reference. The "%d" format conversion specifier for the printf
function family expects an integer argument, not a pointer to an
integer.
} fclose(file); /* now close the file */
return 0; }
HTH
Regards
--
Irrwahn
(ir*******@freenet.de)
Les Coover wrote: "Thomas Matthews" <Th**********************@sbcglobal.net> wrote in message news:m6******************@newssvr32.news.prodigy.c om...
I have read your references, other references and the text book and still cannot get this. Could you give me another clue. Following code still has a problem
/* jeto.c */
#include <stdio.h> #include <string.h>
int main(void) { FILE *file; /* FILE pointer */ int em_no; char store[100]; /* create a file for writing */ file = fopen ("jeto.txt", "w"); while(scanf ("%d %99s", &em_no, store)== 2)
The function scanf() reads input from the console stream.
The function scanf() is evil: http://www.eskimo.com/~scs/c-faq/q12.20.html { printf("Enter, Example: 01 Les L 01/02/04 ", "2300 06:00AM SW Nashville R 01/06/04 ", "2400 10:00PM SW Kansas City");
Character literals can be concatenated by the compiler:
printf("Enter, Example: 01 Les L 01/02/04 "
"2300 06:00AM SW Nashville R 01/06/04 "
"2400 10:00PM SW Kansas City");
Note the elimination of the commas (',').
Also, you should use '\n' for line breaks. The printf()
function does not automatically insert them. fprint(file, "%d %50s\n", &em_no, store);
The first parameter should not be a pointer / address.
For %d format, fprintf() requires a value.
} fclose(file); /* now close the file */
return 0; }
Les
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE * out;
out = fopen("junk.txt", "w");
if(!out)
{
fprintf(stderr, "Error opening file.\n");
return EXIT_FAILURE;
}
fprintf(out, "Text written to a file.\n");
fclose(out);
return EXIT_SUCCESS;
}
--
Thomas Matthews
C++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq: http://www.raos.demon.uk/acllc-c++/faq.html
Other sites: http://www.josuttis.com -- C++ STL Library book
"Les Coover" <lc******@cox.net.spam> writes: I have read your references, other references and the text book and still cannot get this. Could you give me another clue. Following code still has a problem
/* jeto.c */
#include <stdio.h> #include <string.h>
You still don't need <string.h>. int main(void) { FILE *file; /* FILE pointer */
This is obvious enough that there is no need to add a comment
declaring this fact.
int em_no; char store[100]; /* create a file for writing */ file = fopen ("jeto.txt", "w"); while(scanf ("%d %99s", &em_no, store)== 2) { printf("Enter, Example: 01 Les L 01/02/04 ", "2300 06:00AM SW Nashville R 01/06/04 ", "2400 10:00PM SW Kansas City");
You are not using printf() properly. This is pretty much
guaranteed to cause problems. I'd suggest a correction, but the
bottom line is I'm not completely sure what exactly you want it
to do. However, for whatever it is you're trying to do, I *am*
pretty sure that you only want to pass one single argument to
printf(): There should be only one pair of double-quotes, and no
commas, unless you want them *inside* the strings (or possibly,
you might use fgets).
Also, you're scanning for input *before* you are prompting for
it. Once you get the order of operations sorted out, you'll
probably discover you'll need to fflush(stdout) to be safe.
--
Micah J. Cowan mi***@cowan.name This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andras Gilicz |
last post by:
Hi VB fans
I'm working on a relatively large project in VB6 with about a dozen
forms, including graphs, labels, text boxes, etc. The software itself
is actually a flow simulator with more or...
|
by: a |
last post by:
Save text file as html kloepper 17:42 23 Jul '04
I'm using httpwebresponse and a StringBuilder to return a stream that originates as a file with the .txt suffix (My download code converts the html...
|
by: Glenn M |
last post by:
I have a shared XML file on a server .
i also have one xslt file that performs a simple transform on in to
view the data.
now i want to have another page that lets users modify the shared xml...
|
by: david.lindsay.green |
last post by:
Hello all, I am quite new a web scripting and making web pages in
general and I have stumbled across a problem I have as yet been unable
to solve. I am trying to take the contents of a textarea box...
|
by: nuhura01 |
last post by:
Hi..
I'm trying to save query path which is in text box to text file. Below
is the coding that i'm using currently:
Private Sub SaveQueryPath()
'save to text file
Response.Clear()...
|
by: amrhi |
last post by:
Hy Guys , Can anybody help me ?
I try to make small web database in my unit.
Some of fields have on change behaviour to get other data that automatically filled other text field. But when i try to...
|
by: crazyyellowguy |
last post by:
hi,
This is my first post in this forum and I just wanted to thank you for even taking a look at my post. The class that I am writing the C code for is my first computer class and my knowledge is...
|
by: sufian |
last post by:
Below is the field where user enters his/her email address and the AJAX post request is sent to the server and the user sees the message:
echo("<div id=\"message\" class=\"success\">Thank you! You...
|
by: Lamer |
last post by:
I was wondering how to save PHP variables to a txt file and then
retrieve them again.
Example:
There is an input box, after submitted the stuff that was written in
the input box will be saved...
|
by: chennaibala |
last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading.
i develop...
|
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: 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: 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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
| |