Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-14-2008, 06:03 PM
erabyss erabyss is offline
Newbie
 
Join Date: Sep 2008
Posts: 6
Rep Power: 0
erabyss is on a distinguished road
Default file i/o

I am writing a "labyrinth" style game. Minus the maze, because lack of graphic abilties. I used an array to mark the dimensions of the room. and with every step, I force the player to solve a problem.

I wrote the program below to write the "list" function for me. All that is left is to add the questions and answers. I need a program that can read from "file_A", which has a list from all my Q&A, and write to "file_B".

I know how to read from a file. But not how to copy specific lines of text. Do you know where I can find to code that will allow me to do that?

Thank you for your help. I cant wait to have this game finished.

Code:
#include <fstream>
#include <iostream>

using namespace std;

int main()
{
  int x;
  int y;
  
  ofstream a_file ( "list.cpp", ios::app );

  a_file<<"void list() \n{\n\nstring word2;\n\n";
  
  for ( x = 0; x < 4;x++ ) {
    for ( y = 0; y < 4; y++ )
 

  a_file<< "    if ((x == " << x << ") && (y ==" << y << "))\n    {"
    << "\n        string word2 = question(,,,); \n    }\n\n";
 
  }
a_file.close();

}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-15-2008, 12:40 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,376
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default Re: file i/o

It will depend on the layout of the file.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-15-2008, 06:02 PM
erabyss erabyss is offline
Newbie
 
Join Date: Sep 2008
Posts: 6
Rep Power: 0
erabyss is on a distinguished road
Default Re: file i/o

Thats fine. I can set the file up any way I need to. If you can just point me towards a guide/tutorial that can show me how to write a program to do what I need. Or show me a code that I can look at and learn from. That would be awesome.

The way I have my program set up is: The functions that handles the questions returns 3 values.
1- The type of question it is.
2- The question the player needs to solve.
3- The answer to the question.

The guides I have been using only teach the basics of reading and writing to a file. What I use in the program above is as far as it goes. I can write to a file, append to a file, copy over a file, or print the texts of a file. I have no more control than that atm. I have looked but I havent found anything only that a noob like me can understand. I need to see a program to know how to use the code.

Thank you for all your help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-16-2008, 11:43 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,376
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default Re: file i/o

In that case, the getline (I think) function is probably going to be your key. Have each piece of info on its own line, and read the data in line by line.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-16-2008, 02:31 PM
erabyss erabyss is offline
Newbie
 
Join Date: Sep 2008
Posts: 6
Rep Power: 0
erabyss is on a distinguished road
Default Re: file i/o

=] Thank you WingedPanther, I will go look that up now. I'll post my results, so you know if it worked ot not. Thanks again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Project: ionFiles - Joomla Simple File Download Jordan Community Projects 331 11-26-2008 12:35 PM
File Manager Jaan Community Projects 45 08-27-2008 12:11 PM
What mode should i use at fopen()? r, r+, w+b??? tirengarfio C and C++ 3 08-14-2008 12:06 AM
Visual Studio 2008: C# Reading Files Jordan CSharp Tutorials 8 06-20-2008 11:54 AM
Windows Shortcut List - Saves Time 2stamlers The Lounge 6 04-10-2008 07:58 AM


All times are GMT -5. The time now is 03:41 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%

Ads