garbge value in the output..~.~

hi,
when i display my array of charecter it displays the massage inside it
and some junk values were i have sepecified the size of the array and what
it displays is beyond the size.
please is there any one that can tell me what can be the problem,
this is the code in case
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
char m[100];
int size;
    input.getline(m, 100, '\n');
	 size= strlen(m);
	 cout<<m<<endl;
     int empty=10-(size%10);// get number of pits to be padded
	const int newSize=empty+size;
	  char *newFrams =NULL;
	  newFrams=new char[newSize];
	 if(empty!=0 && empty!=10)  //do the padding
		 for(int i=size;i<(empty+size);i++) 
       		m[i]='0';		
	// create new array of Frames
	 for(int x=0;x<newSize;x++)
	 { newFrams[x]=m[x];
	    cout<<" the data in the index "<< x <<" is " <<newFrams[x]<<endl;
	 }
    //update the values after padding
     int Fnums=(newSize)/(10);
	 cout<<endl<< " the mssage is "<<newFrams<<"omima omima omima "<<endl;
     cout<< " the size of the new mssage is ;" << newSize;
	 cout<<" the number of frames to be cheacked are "<<Fnums;
	input.close();



thanx in advance ^^
'newFrams' requires the trailing 0. On line 9 write
1
2
newFrams=new char[newSize+1]; // Note: +1
newFrams[newSize] = 0; // cout needs this in order to determine the end of the string 

Topic archived. No new replies allowed.