473,382 Members | 1,252 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,382 software developers and data experts.

text files

7
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
Dec 12 '06 #1
4 1216
horace1
1,510 Expert 1GB
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?
Dec 12 '06 #2
cv87cv
7
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.
Dec 12 '06 #3
http://www.thescripts.com/forum/thread576670.html
Dec 13 '06 #4
horace1
1,510 Expert 1GB
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.
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. char firstname[20],lastname[20];
  6. int mark;
  7. int x;
  8. FILE *f;
  9. f = fopen("black.txt","w");
  10. for(x=1; x<=5; x++)
  11. {
  12. printf("Enter a name \n");
  13. scanf("%s%s",firstname, lastname);
  14. printf("Enter a mark \n");
  15. scanf("%d",&mark);
  16. fprintf(f,"%s %s mark %d\n",firstname, lastname, mark);
  17. }
  18. fclose(f);
  19. return 0;
  20.  
are you planning to use C or C++ as you had included header files from both?
Dec 13 '06 #5

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

Similar topics

27
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...
0
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...
16
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?
0
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...
3
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....
10
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...
5
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...
29
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,...
1
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...
0
Debadatta Mishra
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...
1
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...
0
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...
0
isladogs
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...
0
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...
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
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.