Question:
Problems with my program. In need of a helping hand.?
Ashely
2013-06-27 20:25:19 UTC
Here are the questions:

1. Create a data file called friends.dat using any text-based editor and enter at least three records storing your friends’ first and last names. Make sure that each field in the record is separated by a white space.

2.Using the friends.dat file from challenge number one, build another program that uses the fscanf() function for reading each record and printing field information to standard output until the end-of-file is reached. Include an error-handling routine that notifies the user of any system errors and exits the program.

Here is the code that I have so far:

#include
#include
#include

int main (void)
{
FILE *inFile;
char tmp[10];
size_t stringLength;
int output;
int count;
count = 1;
inFile = fopen (“\friends.dat”, “r”);
if (!inFile)
{
fprintf (stderr, “could not open file %s for read!\n”, “friends.dat”);
exit (EXIT_FAILURE);
}
while (1)
{
char *tmpString;
output = fscanf (inFile, “%s”, tmp);
stringLength = strlen (&tmp);
tmpString = (char *) calloc stringLength, sizeof (char));
strcpy (tmpString, tmp);
if (count %2 == 0)
fprintf (stdout, “%s\n”, tmpString);
else
fprintf (stout, “%s\n”, tmpString);
if (output == EOF)
break;
count ++;
}

Here is what is in my friend.dat file:
Robert Mandino, 24, #1122332, Floor Echo -1

Sarina Larso, 25, #2211331, Floor Echo -2

Chris Murdock, 29, #3311223, Floor Echo -3

Here are the errors I keep recieving:
C:\Users\student\Desktop\Untitled1.c In function `main':
12 C:\Users\student\Desktop\Untitled1.c stray '\147' in program
12 C:\Users\student\Desktop\Untitled1.c stray '\' in program
12 C:\Users\student\Desktop\Untitled1.c `friends' undeclared (first use in this function)
(Each undeclared identifier is reported only once for each function it appears in.)
12 C:\Users\student\Desktop\Untitled1.c stray '\148' in program
12 C:\Users\student\Desktop\Untitled1.c stray '\147' in program
12 C:\Users\student\Desktop\Untitled1.c stray '\148' in program
12 C:\Users\student\Desktop\Untitled1.c `r' undeclared (first use in this function)
15 C:\Users\student\Desktop\Untitled1.c stray '\147' in program
15 C:\Users\student\Desktop\Untitled1.c `could' undeclared (first use in this function)
15 C:\Users\student\Desktop\Untitled1.c syntax error before "not"
15 C:\Users\student\Desktop\Untitled1.c stray '\' in program
15 C:\Users\student\Desktop\Untitled1.c stray '\148' in program
15 C:\Users\student\Desktop\Untitled1.c stray '\147' in program
15 C:\Users\student\Desktop\Untitled1.c stray '\148' in program
21 C:\Users\student\Desktop\Untitled1.c stray '\147' in program
21 C:\Users\student\Desktop\Untitled1.c syntax error before '%' token
21 C:\Users\student\Desktop\Untitled1.c stray '\148' in program
22 C:\Users\student\Desktop\Untitled1.c [Warning] passing arg 1 of `strlen' from incompatible pointer type
23 C:\Users\student\Desktop\Untitled1.c syntax error before "stringLength"
26 C:\Users\student\Desktop\Untitled1.c stray '\147' in program
26 C:\Users\student\Desktop\Untitled1.c syntax error before '%' token
26 C:\Users\student\Desktop\Untitled1.c stray '\' in program
26 C:\Users\student\Desktop\Untitled1.c stray '\148' in program
28 C:\Users\student\Desktop\Untitled1.c stray '\147' in program
28 C:\Users\student\Desktop\Untitled1.c stray '\' in program
28 C:\Users\student\Desktop\Untitled1.c stray '\148' in program
32 C:\Users\student\Desktop\Untitled1.c syntax error at end of input
Three answers:
?
2013-06-29 03:05:08 UTC
in

inFile = fopen (“\friends.dat”, “r”);

either remove the leading "\" or write an escaped path string such as:

"c:\\users\\student\\desktop\\friends.dat"

(notice the double slashes: "\\")
anonymous
2016-12-25 00:00:47 UTC
1
magdalen
2016-04-27 15:05:30 UTC
If you wish to train your child easily how to learn then Children Learning Reading from here https://tr.im/ekOAu will help you.

Children Learning Reading is produced by small instructions, enough to hold the attention period of a small kid but can also be efficient enough to teach the kid to learn — even at a really early age.

This program is situated about a principle named phonemes, which are (in very simple terms), the seems which make up words we use within our everyday language. The program attempts to instruct your child to see by first gathering your child's capacity to see and understand the phonemes that produce up daily words. When your child can try this then they have all the tools they have to begin creating sense of new words, that may consequently produce their studying abilities stronger and stronger.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...