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 02-08-2008, 08:17 AM
boburob boburob is offline
Newbie
 
Join Date: Feb 2008
Posts: 1
Rep Power: 0
boburob is on a distinguished road
Default Reading a text file to an array

Hey im trying to read a text file to an array, but at the moment the array is just staying empty:

Code:
#include <iostream>
#include <fstream>
//This section of the code includes the libaries needed to run the program
using namespace std;

int main() 
//This defines the main() function
{
	char file[256];
	char code[512];
	ifstream inFile;
	system("cls");
	cout << "				Code Breaker!\n" << endl;
	cout << "Please enter the name and extension of the file you want to decode:\n" << endl;
	cin.getline ( file, 256, '\n');
	cout << "The name entered was :\n" << file << endl;
	inFile.open(file);
	if (!inFile) {
		cerr << "Unable to open file";
		exit(1);   
	}
	inFile >> code[512];
	
	cout << "This file contains the code:\n" << code << endl;
	inFile.close();
	return 0;
}
Thanks for your help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 02-08-2008, 08:51 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,651
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

Why don't you use std::strings? And instead of arrays, std::vectors, though arrays nor vectors aren't needed in your code. You can simply load the content into a std::string.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
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
Text file manipulation. joe1986 Python 11 01-28-2008 01:10 AM
How to save the text in a text file ??? kresh7 Visual Basic Programming 0 11-25-2007 11:30 AM
How to style fonts of a text in a simple page? c0de Tutorials 3 09-15-2007 11:08 PM
Usage of array structures to increment letter instances of text Yuriy M C and C++ 2 09-13-2007 11:49 AM
text file manipulations in vb6.0 Ronin_paes Visual Basic Programming 3 06-11-2007 05:54 AM


All times are GMT -5. The time now is 09:42 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%


Complete - Celebrate!

Ads