473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

fscanf values into variables

Hi

I have a function where I scan from a '/' (slash) delimited text file. here is an exteract
Ford/BigTruck/b671asd/fix doors/doorsrus/01-01-04/23328/2000.00/
Chevy/4L Van/B235QWQ/paint rear/colouyrs/02-08-09/32433/2001.00/
HiFlier/5Di/B568ASS/fix rear bumper/automtix/01-08-09/323/425.00
Ford/BigTruck/b671asd/remove dents/fifi/12-03-11/12345/300.00/

I want to extract lines from the text file base on the license registration, which is the third field. so this is my code:


repair_reports()

{
FILE *zfile;
int Found=0;
zfile= fopen ("repair.dat","r");

printf("\n Enter Registration Number: ");

gets(registration);

while (!feof(zfile))
{
fscanf(zfile,"%19[^/]/%[^/]/%[^/]/[^/]/%[^/]/%[^/][^/]/d/",vehicle_name,model,registration_number,short_des cription,garage_mechanic,repair_date,invoice,&Amt) ;
if (feof(zfile))
break;
}
//string that compares to registration name
if (strcasecmp(registration,registration_number)== 0)
Found = 1;

if (Found)
{
printf("Vehicle_name: %s\n", vehicle_name);
printf("model: %s\n", model);
printf("Registration Number: %s\n", registration_number);

fclose(zfile);
system("pause");
}
else
printf(" No Repairs Found ");

system("pause");
}

}
The problem is: the comparison fails since it does not pick the right field for registration_number
Aug 5 '11 #1
1 1468
weaknessforcats
9,208 Expert Mod 8TB
I have not seen this before:

Expand|Select|Wrap|Line Numbers
  1. fscanf(zfile,"%19[^/]/%[^/]/%[^/]/[^/]/%[^/]/%[^/]....
what does [^/] mean? I expected things like %d, %s, etc.
Aug 5 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Marc Reclaire | last post by:
Hiho, I have an ASCII-File with data from a simulation programm. It lookslike this: 2.500000E+0026.911733E+0022.950929E+0054.746349E+0040.000000E+0000.000000E+0 00...
7
by: Sam | last post by:
Hi everyone This some sort relates to a question that posted couple of day ago. Basically I have a text file which consists of number of lines with the following format. Each line is terminated...
3
by: Avlan | last post by:
Still new with asp, and I feel I haven't yet captured the logic of it completely ;-P I know how to post values to another asp-page through the use of a form and a submit-button, combined with...
2
by: raji20 | last post by:
This is my first page named test.php, In this page iam assigning the value to the session variable username,and I could able to access that value in this page. But when I access the same...
9
by: quyvle | last post by:
I can't seem to get this function to work correctly. I'm wondering if anyone could help me out with this. So I'm using the fscanf function to read the input stream and store each string in the...
0
by: elegipcio | last post by:
Hello everyone i'm new to asp.net i'm looking to How to get values (Variables) pre Declared in web form & pass it to a batch file. coz i've to get this values to be added to the batch file to...
2
by: DLN | last post by:
Hello all, I apologize for the naivety of this question, but I'm wondering whether session variables can ever be modified (somehow) by a client without having to go through code that I write. ...
5
by: imailz | last post by:
Hi all, since I'm forced to switch from Fortran to C I wonder if there is posibility in C: 1) to use implicit loops 2) to parse several variables which number is determined at runtime. ...
42
by: Bill Cunningham | last post by:
I'm doing something wrong and all I know to do is turn to clc. I have a text file containing 2 doubles separated by a tab. ..26 0 Is the text. I want to read the two double and printf them...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.