Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5428
Number of posts: 16949

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
pointers on text file? Posted by AvarageJoe on 21 Nov 2012 at 2:33 PM
Hi everybody..

I have a question about pointers and text files..

Well the case is so, that I have write a program for shcool, where I got a long list of soccer games as txt file.
I have to use that txt. to find out on which of the matches the teams have scoret most of the goals.

Now the problem here is, I don't have a clue about, how I can use the data that is inside the txt..

This is what I have for now..
#include <stdio.h>
#include<string.h>
#define MAX_LEN 200

int main(void)
{
  FILE *inp;
  char name[MAX_LEN], name2[MAX_LEN];
  int score;
  long maal;

   inp =fopen("superliga.txt", "r");
   
    if (inp != NULL) {
	
	fscanf(inp, "%s ", name);

	 printf("%s ", name);
	 fclose(inp);
	}
	else {
	 printf("Cannot find the file");
	 }
	 
	 return 0;

}


- Is there a way to use sscanf on the file??
I want to be able to get some data from the txt file and be able to do some math and print it out again..
Any idea is appreciated



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.