Hi, Guys
I am a beginner please help me.
I wrote something like this:
#include <iostream.h>
#include <string.h>
#define number 1
#define length 35
char student[number][length];
int i,j,k;
char *BlankImprover(char *);
void InsertInfos(void);
void main(){
InsertInfos();
for(i=0;i<number;i++)
for(j=0;j<15;j++)
cout<<student[i][j];
}
void InsertInfos(){
char name[15];
for(i=0;i<number;i++){
cout<<"Enter Student Number <"<<i+1<<"> Informations:"<<endl;
cout<<"Enter Student First Name(MAX: 15 Characters) : ";
cin>>name;
char *NBName = BlankImprover(name);
for(j=0;j<15;j++)
student[i][j] = NBName[j];
}
}
char *BlankImprover(char *string){
char *BlankPattern="###############";
strcpy(BlankPattern,string);
//For Deleting NULL value from String
for(i=0;i<15;i++){
if(BlankPattern[i]=='#')
BlankPattern[i-1]='#';
}
return BlankPattern;
}
I created a global 2D array and in InsertInfos() Function Inserts a string to elements 0 to 14 of array and if length of string inserted by user is less than 15 chars the BlankImprover(char *string) Function Fills rest of string by '#'. the Regenerated String will put on array.
EX: CIN>>name -->"mahdi"
VALUE TO Fill The Array: "mahdi##########"
other elements of array Student[][] will fill later. bu the problem is this:
in main() block ,cout<<student[j]; does not outputs "mahdi##########" in first 15 elements of array and prints null value. infact the text user inserted does not exist in array. please help me! why?
what is my mistake?