I am trying to answer a question with regards to entering a set of numbers and text, and then I have got to search for a number and the text with it.
This is the code that I have written for inputting the numbers:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main()
{
char name[20];
int mark;
int x;
FILE *f;
f = fopen("black.txt","w");
for(x=1; x<=5; x++)
{
printf("Enter a name \n");
gets(name);
printf("Enter a mark \n");
scanf("%d",&mark);
fprintf(f,"%s %d\n",name, mark);
}
fclose(f);
return 0;
}
it will not input the number and mark correctly together
the other part of the code to display a certain number and text is :
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main()
{
char name[20];
int number;
int x;
FILE *f;
f = fopen("black.txt","w");
while ( fscanf(f,”%s”,name )
{
if (number=10)
{
printf(“%s \n”,name);
}
}
fclose(f);
return 0;
}
this part is not working properly either and I am unable to spot what is wrong with it. i think because i've been looking at it for a while i just cant see the problems
so if someone can help me that would be great
4 1216
I am trying to answer a question with regards to entering a set of numbers and text, and then I have got to search for a number and the text with it.
so if someone can help me that would be great
how do you want to format the name and mark because that determines how you read the information, e.g.
(1) two lines
Sam Jones
45
(2) one line
Sam Jones 45
will you always have a fist name and last name, can you have a middle name, etc?
how do you want to format the name and mark because that determines how you read the information, e.g.
(1) two lines
Sam Jones
45
(2) one line
Sam Jones 45
will you always have a fist name and last name, can you have a middle name, etc?
yea there will always be a first and last name, no middle name. the name will be on a different line to the number which is given to each person.
http://www.thescripts.com/forum/thread576670.html
yea there will always be a first and last name, no middle name. the name will be on a different line to the number which is given to each person.
you could have seperate variables for first and last name, e.g. -
#include <stdio.h>
-
-
int main()
-
{
-
char firstname[20],lastname[20];
-
int mark;
-
int x;
-
FILE *f;
-
f = fopen("black.txt","w");
-
for(x=1; x<=5; x++)
-
{
-
printf("Enter a name \n");
-
scanf("%s%s",firstname, lastname);
-
printf("Enter a mark \n");
-
scanf("%d",&mark);
-
fprintf(f,"%s %s mark %d\n",firstname, lastname, mark);
-
}
-
fclose(f);
-
return 0;
-
}
-
are you planning to use C or C++ as you had included header files from both?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Eric |
last post by:
Assume that disk space is not an issue
(the files will be small < 5k in general for the purpose of storing
preferences)
Assume that transportation to another OS may never occur.
Are there...
|
by: Steve |
last post by:
My application uses transfertext to create text files that are FTPed to a
website and are processed by a webstore. The text files can be for one of three
purposes: Add one or more items to the...
|
by: thenightfly |
last post by:
Ok, I know all about how binary numbers translate into text characters.
My question is what exactly IS a text character? Is it a bitmap?
|
by: richardkreidl |
last post by:
I have the following hash script that I use to compare two text files.
'Class
Public Class FileComparison
Public Class FileComparisonException
Public Enum ExceptionType
U 'Unknown
A 'Add...
|
by: Frustrated Developer via DotNetMonster.com |
last post by:
I have posted a couple times on here already and found the user community to
be very helpful. I took on a project before I realized how difficult a time
I'm having working with a database....
|
by: joelagnel |
last post by:
hi friends,
i've been having this confusion for about a year, i want to know the
exact difference between text and binary files.
using the fwrite function in c, i wrote 2 bytes of integers in...
|
by: praveenholal |
last post by:
Hi Freinds ,
I want to convert the files that are in text format (.txt) to CSV file. I am working on Linux. So can anyone guide me.
Here is my problem Description
I have some result files...
|
by: list |
last post by:
Hi folks,
I am new to Googlegroups. I asked my questions at other forums, since
now.
I have an important question: I have to check files if they are
binary(.bmp, .avi, .jpg) or text(.txt,...
|
by: Xah Lee |
last post by:
Text Processing with Emacs Lisp
Xah Lee, 2007-10-29
This page gives a outline of how to use emacs lisp to do text
processing, using a specific real-world problem as example. If you
don't know...
|
by: Debadatta Mishra |
last post by:
Introduction
In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
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: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
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:
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |