|
I wrote a piece of RLE code. . The function is. . Enter a string of characters. . . In these strings, if the number of repetitions exceeds 3, N ¥ T is used, where N is the number of repetitions. ¥ indicates that the control symbol is repeated here. T represents repeated characters. Everything else is output directly.
code show as below.
#include <stdio.h>
#include <string.h>
void main ()
{
char code [100];
int repcount = 0, i, j;
printf ("please input the code:\n");
scanf ("% 100s", code);
puts (code);
for (i = 0; code [i]! = '\0'; i ++)
{
if (code [i]! = code [i + 1]&&repcount <1)
printf ("% c",&code [i]);
else
{
if (code [i] == code [i + 1])
repcount ++;
else
{
if (repcount> = 4)
{
printf ("% d $% c",&repcount,&code [i]);
repcount = 0;
}
else
{
for (j = 0; j <repcount; j ++)
printf ("% c",&code [i]);
repcount = 0;
}
}
}
}
getch ();
}
After compiling. . run. . The results obtained are garbled. .
I use FOR control directly. . Output each element in the array code directly. Discovery is also garbled. . This shows that I have a problem with PRINTF output. . But I can use puts (code) to output normally. . . Anyone tell me what's going on. .
In addition, I want to write a video display program under VFW (VIDEO FOR WINDOWS). . I have the reference code here. . But I don't know what to use in C. . Does anyone tell me about it. How to use API novice in C, no programming experience under Windows. . I hope you seniors give pointers. |
|