help with homework array

I think i'm just confused. I need to read text from a file put it into an array, with 4 characters in each element.

does the inputFile.open when putting it into an array seperate each element automatically when it sees a space? when I print the array out it shows the whole file, so i can't tell if it's doing one character at a time, or all of it.

my crappy code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//prototyping
char showArray(char[],int size);
bool decode(char[], int size);



int main()
{
   const int ARRAY_SIZE = 128; // Array size, because each note has 4 characters
   const int THISNOTE = 4;		//how many characters are in each note
   char numbers[ARRAY_SIZE];    // Array with 512 elements
   char mp3[THISNOTE][2];
   int count = 0;              // Loop counter variable
   int temp;			//temps counters
   ifstream inputFile;         // Input file stream object
   
   inputFile.open("sound.dat"); // Open the file.
   
  
   while (count < ARRAY_SIZE && inputFile >> numbers[count])
     
	
    decode(numbers, ARRAY_SIZE);
      
       count++;
        
   // Close the file.
   inputFile.close();



   return 0;
}

bool decode(char name[], int size)
{
	bool status;
	
	  if(name[0] >='0' && name[0] <='7')
		{
		status =  true;
		cout << name[0];
        } 
	else
		{
		status = false;
		cout << name[0];
		}

      
	return status; 	 
	
}




char showArray(char name[],int size)
{
	int octav;
	
	  if(name[0] >='0' && name[0] <='7')
    {
		
		 octav = name[0];             
		 
        } 
	else
	{
		//cout <<  name[0];    
	}



return octav;
     


Last edited on
Honestly this code makes no sense to me. What in the world are you trying to do?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
inputFile.open("sound.dat"); // Open the file.
   
  
   while (count < ARRAY_SIZE && inputFile >> numbers[count])
     
	
    decode(numbers, ARRAY_SIZE);  //what this piece of code have to do here???
      
       count++;
        
   // Close the file.
   inputFile.close();  //why do you close you file ? it's not finish yet!!



also you are missing some brackets {} around your while loop.
Last edited on
Topic archived. No new replies allowed.