#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main(){
ifstream inFile;
const int SIZE = 81;
char name[SIZE];
inFile.open ("mycities.txt");
inFile >> name; //1st word
cout << name;
inFile >> name; // 2nd word
cout << setw(4) << name;
inFile >> name; //3rd word etc.
cout << name;
inFile.close();
cout << "Done";
system ("PAUSE");
return 0;
}
The text file as of right now doesn't have the temperatures ordered numerically from coldest to hottest, which is what I have to do. Basically he says we should use a while loop to do this, but I'm unsure how to specify which "name" to use if they're all called "name". How do I specify which word/number I want to arrange where when they're all called name?
I'm also confused as to what he means here :Use constants to define the size of the arrays and the max number of characters in a city/province name.
Specify the name arrays as char[SIZE][NAME_LENGTH], where SIZE is the number of cities (10 in our case) and NAME_LENGTH is a constant, set it to 64.
Use a temporary variable to swap elements in the array, in 2 steps …
To copy strings either:
Use a while loop to copy all elements up-to and including the terminating null character ‘\0’; or Use strcpy(dst, src) function and include <string.h> , recommended.
This is kind of confusing to me, does anyone know a good basic tutorial for arrays?
Thanks.
This post has been edited by Munchiester: 15 October 2010 - 01:19 PM

New Topic/Question
Reply




MultiQuote










|