| |

VerySource

 Forgot password?
 Register
Search
View: 847|Reply: 3

Found a problem. . Hope to tell the answer.

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-18 05:40:01
| Show all posts |Read mode
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.
Reply

Use magic Report

0

Threads

78

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 United States

Post time: 2020-1-25 18:45:01
| Show all posts
Remove the address symbol&from the printf parameter
Reply

Use magic Report

0

Threads

78

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-1-25 20:09:01
| Show all posts
It seems that there is something wrong with the logic. I modified it a bit:
When repeated more than 3 times (excluding 3 times),
Output Repeatability Results:

#include <stdio.h>
#include <stdlib.h>

int 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\n", code [i]);
        else
        {
            if (code [i] == code [i + 1])
            repcount ++;
            else
            {
                if (repcount> = 3)
                {
                    printf ("% d $% c\n", repcount + 1, code [i]);
                    repcount = 0;
                }
                else
                {
                    for (j = 0; j <= repcount; j ++)
                    printf ("% c", code [i]);
                printf ("\n");
                    repcount = 0;
                }
            }
            
        }
    }


    system ("PAUSE");
    return 0;
}
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-26 15:18:01
| Show all posts
Thank you for your reply. . It's my idea. . . Not paying attention to this. . Ha ha. . . The logic is a bit problematic. . I forgot. . . Because there is a problem with the test. . So there is no question of logic.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list