Simple file I/O question

This is a discussion on Simple file I/O question within the C++ Programming forums, part of the General Programming Boards category; Do you have to output to a file first and then input from it? Or can you just tell the ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    33

    Cool Simple file I/O question

    Do you have to output to a file first and then input from it? Or can you just tell the input to point to a location for the file? Also since i am already here. How can i get it to read a line, check it and if not what its looking for go back to the file and read the second line and so on and so on? Any tutorials would be nice. Sorry for not posting code. If you need more info i will try to post code. Thanks.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    33
    Ok i figured out how to point to a file on my computer to read from. But i am still looking to find out how to read line after line. thanks for any help

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    33
    Ok here is my code (i am doing this just for fun and for my own computer)

    Code:
    #include "stdafx.h"
    #include "iostream.h"
    #include "stdlib.h"
    #include "stdio.h"
    #include "fstream.h"
    #include "string.h"
    
    int main()
    {
    	char infos[30];
    	char ip[30];
    	char infoe[100];
    	char infop[100];
    	char info[100];
    	char pass[10];
    	char test[10];
    	char user[20];
    
    	ifstream a_file("c:/test.txt");
    	a_file>>test;
    
    	strcpy(pass, test);
    		
        cout<<"Command to run:\n";  //Using if for explorer ftp://
    	cin.getline(infos, 30);
    
    	cout<<"Username + :\n";     //Getting accounts user name
    	cin>>user;
    
    	cout<<"@ + IP\n";           //Getting the IP address
    	cin>>ip;
    	
    	strcpy(infoe, infos);
    	strcat(infoe, user);        //Starts combining info
    
    	strcpy(infop, infoe);
    	strcat(infop, pass);
    
    	strcpy(info, infop);
    	strcat(info, ip);           //Finishes combining info
    
    	system(info);
    
    	return 0;
    }
    That code works for my just fine for now. Like i asked above, how would i read another line of a file if the first line wasnt what i wanted? Now i need help with finding out if the password is wrong and get it to close the explorer and then start over with a new password until it gets it right. Plz try to just give me some function or what ever to look up on google and/or some tutorials that might help me figure this out would be nice. Thanks.

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    ignore the top part if your compiler complains about the changes... just newer standards... ask somebody else about stdafx and stdio... I think it's <cstdio>, but i'm not sure...
    Code:
    #include <stdafx.h> //not sure about this one
    
    #include <iostream>
    #include <cstdlib>
    #include <stdio.h> //not sure about this one either
    #include <fstream>
    #include <cstring>
    
    using namespace std;
    
    int main()
    {
    	char infos[30];
    	char ip[30];
    	char infoe[100];
    	char infop[100];
    	char info[100];
    	char pass[10];
    	char test[10];
    	char user[20];
    
    	ifstream a_file("c:/test.txt");
    
                    do{
                         a_file>>test;
                    }while(!strcmpi(test,"compare to this")); 
    
                     //something like that ^
    
    	strcpy(pass, test);
    		
        cout<<"Command to run:\n";  //Using if for explorer ftp://
    	cin.getline(infos, 30);
    
    	cout<<"Username + :\n";     //Getting accounts user name
    	cin>>user;
    
    	cout<<"@ + IP\n";           //Getting the IP address
    	cin>>ip;
    	
    	strcpy(infoe, infos);
    	strcat(infoe, user);        //Starts combining info
    
    	strcpy(infop, infoe);
    	strcat(infop, pass);
    
    	strcpy(info, infop);
    	strcat(info, ip);           //Finishes combining info
    
    	system(info);
    
    	return 0;
    }
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    33

    Talking

    Thanks for the help but when i added the do while loop like u had it and change the " " to what i wanted and tried to cout the var pass it didnt output anything but a blank line. BTW does anyone know how to end a process??? i thought i had it and got these errors:

    C:\Program Files\Microsoft Visual Studio\MyProjects\ftp\ftp.cpp(49) : error C2664: 'GetExitCodeProcess' : cannot convert parameter 1 from 'int' to 'void *'
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

    C:\Program Files\Microsoft Visual Studio\MyProjects\ftp\ftp.cpp(51) : error C2664: 'TerminateProcess' : cannot convert parameter 1 from 'int' to 'void *'
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

    Here is my code now:

    Code:
    #include "stdafx.h"
    #include "iostream.h"
    #include "stdlib.h"
    #include "stdio.h"
    #include "fstream.h"
    #include "string.h"
    #include "windows.h"
    
    int main()
    {
    	char infos[30];
    	char ip[30];
    	char infoe[100];
    	char infop[100];
    	char info[100];
    	char pass[10];
    	char test[10];
    	char user[20];
    	int HANDLE;
    	int LPDWORD;
    	
    	
    	ifstream a_file("c:/test.txt");
    	a_file>>test;
    
    	strcpy(pass, test);
    		
        cout<<"Command to run:\n";  //Using if for explorer ftp://
    	cin.getline(infos, 30);
    
    	cout<<"Username + :\n";     //Getting accounts user name
    	cin>>user;
    
    	cout<<"@ + IP\n";           //Getting the IP address
    	cin>>ip;
    	
    	strcpy(infoe, infos);
    	strcat(infoe, user);        //Starts combining info
    
    	strcpy(infop, infoe);
    	strcat(infop, pass);
    
    	strcpy(info, infop);
    	strcat(info, ip);           //Finishes combining info
    
    	system(info);
    
    	HANDLE=GetCurrentProcessId();
    	GetExitCodeProcess(HANDLE, LPDWORD);
    
    	TerminateProcess(HANDLE, LPDWORD);
    
    	return 0;
    }
    This is just a program for fun and to mess around. I am hoping it will be able to read from a wordlist and try different passwords for my ftp until it gets it write. If you have any suggestions on if i should try a different route that would be great. Like i said this is just my own fun little project. Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple file I/O problem
    By eecoder in forum C Programming
    Replies: 10
    Last Post: 10-16-2010, 11:00 PM
  2. C++ File I/O question
    By zero_cool in forum C++ Programming
    Replies: 3
    Last Post: 08-16-2005, 10:43 AM
  3. File I/O question... please help!
    By sirSolarius in forum C++ Programming
    Replies: 11
    Last Post: 10-07-2003, 08:30 AM
  4. File I/O Question
    By DocDroopy in forum C Programming
    Replies: 4
    Last Post: 08-02-2002, 08:58 AM
  5. I have a file I/O question as well
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 03:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21