www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/13/04:18:13

From: "jo" <johne AT nospam DOT cromnet DOT net DOT au>
Newsgroups: comp.os.msdos.djgpp
Subject: File i/o , strings in c++ help a beginner.
Date: 13 May 1998 06:55:40 GMT
Organization: DIALix Internet Services
Lines: 61
Message-ID: <01bd7e3b$310abf00$LocalHost@default>
NNTP-Posting-Host: news AT marconi DOT dialix DOT com DOT au
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I'm slowly learning c++. Have gone through some c tutorials etc and am
currently going through a few c++ ones.

Writing a little program of my own to learn along the way. Started
doing it in c and would now like to convert it to c++.

It involves reading from a text file, looking for certain words and
extracting dates, numbers etc..

In C it uses:
fp1 = fopen("modemlog.txt", "r");
	if (fp1 == NULL)
	{
		printf("File failed open");
		exit (EXIT_FAILURE);
 	}

to open the file for reading, how do I change this to the c++ way?

c = fgets(line, 100, fp1);
		if (c != NULL)
		{
		  ...loop here
		}

line is a char array of 100 elements. Is there a similar c++ 'fgets'
command?
If not how do I change the above snippet to c++? Would like to keep the
checking for the end of file in there too.

Also it uses 'strstr' to check if a certain word is in the 'line'
array, is there a similar c++ function for this?

and similar c++ alternatives to :
strcmp
strcpy
atoi
atof
isspace

I am using djgpp under win95. I've found a libc reference in win help
file format. Is there a libc++ ref that I could download somewhere?

Would also appreciate any good c++ reference sites, I have a couple of
c++ tutorials but they don't really cover file I/O or string handling
in depth, so would appreciate any 'simple' source code, docs, tutes etc
for this sort of thing. I'm an absolute beginner so the simpler the
better.

Thanks for your time.

remove no spam from email

-- 
------------------------------------------------------------------------






- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019