![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How do i change to super user then revert back to ordinary user ,using shell script? | wrapster | Shell Programming and Scripting | 3 | 06-04-2008 04:11 AM |
| switching user from root to ordinary user | sasia | Shell Programming and Scripting | 3 | 01-25-2008 07:25 PM |
| Other than root user .Normal user is unable to create files | mallesh | UNIX for Advanced & Expert Users | 1 | 06-22-2005 09:18 AM |
| Limiting length of user in while creating user | Satya Mishra | AIX | 2 | 04-14-2005 11:40 PM |
| single user mode - user accounts passwords | orestis | UNIX for Dummies Questions & Answers | 2 | 03-09-2005 06:54 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
new c++ user that needs help
I'm in a programming class and I have an assignment where I have to open a file, and count the number of times a certain character apperas that the user input, in that file. I need help in figuring out how to create a function to count the number of occurence of a give characeter, and with any mistakes that I may have made. So far this is what I have
#include "stdafx.h" #include <iostream> using namespace std; // function to find the number of occurences of a character int count_file(ifstream& in_file, int num); int count_file(in_stream, out_stream); int main() { int num, total; //open file input in_stream.open("infile.txt"); if (in_stream.fail()) { cout << "opening input file failed" << endl << "program terminated" << endl; exit(1); } cout << "Enter a charcter that you would like to know whether or not it appears"; cin >> num; // function to find the number of occurences of a character count_file() //open file for output out_stream.open("outfile.txt"); count_file(in_stream, out_stream); // closing files in_stream.close(); out_stream.close(); return 0; } int count_file(ifstream& in_file, int num) { while(! in_file.eof()) { fin.get(num) total = } } // function to output the answer int count_file(in_stream, out_stream) { cout << "The charcetr" << num << "occured" << total << "times"; } Last edited by cold16; 10-28-2007 at 01:11 PM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Simple rules of the UNIX.COM forums:
Rule 6. surely you would do the equivalent of Code:
int count_file(FILE *fpIn,char whatToLookFor)
{
int result=0;
int c;
while (EOF!=(c=fgetc(fpInf)))
{
if (c==whatToLookFor) result++;
}
return result;
}
I think you mean "whether", not "weather". |
|
#3
|
|||
|
|||
|
thankyou for the help
|
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|