Hi, I'm new in C and I found a problem in my program. Could anybody help me to check for me code?
Here is my Codes:
***********************************************************
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <beck.h>
#include <string.h>
void Lcd_Printf(char Rough_Text_Size[16])
{
char Actual_Text_Size[8];
int Actual_Loop=0;
int Rough_Loop=0;
int String_Length=strlen(Rough_Text_Size);
/*read the size of the input text and assign it to String_Length variable*/
printf("%d\n",String_Length);
for (int j=String_Length; j<16;j++)
{
Rough_Text_Size[j]=0x20;
}
/*change all the disuse space in the array to 'SPACE'=0x20*/
while(Actual_Loop<8)
{
if(Rough_Text_Size[Rough_Loop]== '*' && Rough_Text_Size[Rough_Loop+1]=='s')
{
Actual_Text_Size[Actual_Loop]=0x20;
Actual_Loop+=1;
Rough_Loop+=2;
}
else
{
Actual_Text_Size[Actual_Loop]=Rough_Text_Size[Rough_Loop];
Actual_Loop+=1;
Rough_Loop+=1;
}
}
/*convert the "*s" to become a single 'SPACE'=0x20*/
for(int g=0; g<8 ;g++)
printf("%c",Actual_Text_Size[g]);
printf("\n");
/*print the characters*/
for (int n=0; n<16; n++)
{
Rough_Text_Size[n]=0;
}
/*reset the Rough_Text_Size array to null*/
}/*end of Lcd_Printf function*/
void main(void)
{
Lcd_Printf("hhhhhh");
Lcd_Printf("abcdef");
}
/*End of main program*/
***********************************************************
I expected the output in the screen will be:
6
hhhhhh
6
abcdef
But this program gave me the output as below:
6
hhhhhh
0
this told me that the Rough_Text_Size array values were change. However, I can't find out why. Could any expert tell me why? and what should I change in my code so that I could get the output that I expected? Thank you!
Here is my Codes:
***********************************************************
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <beck.h>
#include <string.h>
void Lcd_Printf(char Rough_Text_Size[16])
{
char Actual_Text_Size[8];
int Actual_Loop=0;
int Rough_Loop=0;
int String_Length=strlen(Rough_Text_Size);
/*read the size of the input text and assign it to String_Length variable*/
printf("%d\n",String_Length);
for (int j=String_Length; j<16;j++)
{
Rough_Text_Size[j]=0x20;
}
/*change all the disuse space in the array to 'SPACE'=0x20*/
while(Actual_Loop<8)
{
if(Rough_Text_Size[Rough_Loop]== '*' && Rough_Text_Size[Rough_Loop+1]=='s')
{
Actual_Text_Size[Actual_Loop]=0x20;
Actual_Loop+=1;
Rough_Loop+=2;
}
else
{
Actual_Text_Size[Actual_Loop]=Rough_Text_Size[Rough_Loop];
Actual_Loop+=1;
Rough_Loop+=1;
}
}
/*convert the "*s" to become a single 'SPACE'=0x20*/
for(int g=0; g<8 ;g++)
printf("%c",Actual_Text_Size[g]);
printf("\n");
/*print the characters*/
for (int n=0; n<16; n++)
{
Rough_Text_Size[n]=0;
}
/*reset the Rough_Text_Size array to null*/
}/*end of Lcd_Printf function*/
void main(void)
{
Lcd_Printf("hhhhhh");
Lcd_Printf("abcdef");
}
/*End of main program*/
***********************************************************
I expected the output in the screen will be:
6
hhhhhh
6
abcdef
But this program gave me the output as below:
6
hhhhhh
0
this told me that the Rough_Text_Size array values were change. However, I can't find out why. Could any expert tell me why? and what should I change in my code so that I could get the output that I expected? Thank you!