C Language Issues: Programs that remove whitespace at the end

Updated on technology 2024-02-08
14 answers
  1. Anonymous users2024-02-05

    First question: What does exit failure mean? Why do you need this thing in this program?

    This should be a macro, that is, a value is defined, and it is easy to understand by writing this name.

    define exit failure (-1), otherwise you will directly engage in 1-1 people and they will not know what it means.

    You can know the name when you make it, and the result is a failure, which is easy to read.

    The second question: why is the return statement of the main() function return return instead of return 0

    In fact, the return value of main is returned to the system, and whatever you return has no effect on the program.

    If it is 0, it tells the system that the program is running normally and exits, and if it is other values, it is caused by an exception.

    The third question: why define a function advanse()?This function means +1 in this program. Just use ++. Why is it so much trouble to define a function、?? What is the purpose of it?

    There are two advantages of writing a function, 1 is easy to read, but easy to use, because it is not only +1 but also the judgment of the range of data values.

  2. Anonymous users2024-02-04

    Exit failure is an error when the ejection return value.

    The value returned by return will return different values depending on the result of different operations, return 0 can only return a fixed value, and when there are 0 characters in the middle of the file, it will return exit-failure

    advanse() determines whether the next character is 0.

    It is impossible to have 0 characters in a normal txt text. So it's the same with or without adding this paragraph.

  3. Anonymous users2024-02-03

    Remove the space to the right of the string

    voidvs_strrtrim(char

    pstr) to remove the space to the left of the string

    voidvs_strltrim(char

    pstr)while(*ptmp

    pstr

  4. Anonymous users2024-02-02

    You know there are two mistakes, so why not look for them! Lazy!!!

  5. Anonymous users2024-02-01

    p='\0';p--;

    Modified to: p='\0';p--;

    To assign a value here, of course, you have to use *.

  6. Anonymous users2024-01-31

    p='\0';p--;Here a pointer equals one character???

  7. Anonymous users2024-01-30

    It's easy to do this with regular expressions, and I've made a demo that you can experiment with.

    regex match, the pattern is * pattern ="([\t ]+r\\\0]+" ;

    Then replace the pattern according to the checkbox option to match the space and tab separately

  8. Anonymous users2024-01-29

    First you need to judge i-1>=0, if from[0]='', then from[i-1] doesn't make sense. There are also the last two else I don't understand.,I don't know which if statement the landlord's else corresponds.。 I think the landlord should first read all the input information into the string from, and then detect the '',t',' '。

    This looks more pleasing to the eye, and it's better to add comments to the program so that others can understand it more easily, which is a good habit as a programmer, and by the way, I'm also a rookie, and I just learned the pointer.

  9. Anonymous users2024-01-28

    In the first loop, the value of variable i is the subscript of the last character of the string, and each cycle is minus 1, that is, to judge forward character by character, the condition is isspace(str[i]), if it is a space, subtract 1 again, otherwise it is not a space, then exit the loop, when exiting the loop, i points to the first non-space character at the end of the string, and the string needs to end after this character, so assign the string ending character 0 to str[i+1].

    The second loop i starts from the first character of the string, each loop i adds 1 to find the next character position immediately after it, if it encounters a character that is not a space, stop the loop, and exit the loop so that i points to the first non-space character position of the string.

    Since the first loop has already assigned the string terminator to the string ending non-space character after the position element, the string starting with str+i is the string after the first and last consecutive characters have been removed.

    After the string is output, you can continue to enter the new string until you enter END or enter the carriage return directly, and then the program stops running and exits the while loop, which is the function of the last if statement of the while loop body.

  10. Anonymous users2024-01-27

    p is a pointer to a string of character strings, strlen(s1) returns an integer, and you assign a whole comma data to a pointer, but you don't understand the liquid-based meaning of the pointer.

  11. Anonymous users2024-01-26

    Make a for loop and copy the string to yourself word by word, but skip it when you encounter a space. Examples are as follows:

    #include ""//if the vc++,with this line.

    #include ""

    int main(void)

  12. Anonymous users2024-01-25

    p++;This sentence must be removed from the if clause, because the time of the assignment is borrowed from one by one, and the number p should be read downwards regardless of whether the condition is true or not.

  13. Anonymous users2024-01-24

    replace p++; This sentence is removed from the if clause, and it is executed regardless of whether the if condition is true or false.

    #include

    fun(char * str)

    str[i]=0;

    main()

  14. Anonymous users2024-01-23

    This program is OK, please pay attention to the matching of parentheses when writing the program.

    Otherwise, it is difficult to find the scope of the term.

    Input"aa bb ccc ddd"

    Output"aabbcccddd"

    #include

    int fun(char * str)

    p++;str[i]=0;

    int main()

Related questions
12 answers2024-02-08

This problem requires understanding that the system allocates memory to static variables when compiling, and the memory units occupied by them are not released after the function call ends, that is, the value of the variable is the value of the previous function call at the next function call. >>>More

4 answers2024-02-08

2. 1, True 2, False (there is only one program) 3, False (not necessarily) 4, True. >>>More

7 answers2024-02-08

The first if(!) a) means that if a is equal to zero, take x -- the second and third means that if b and c are not 0, it is executed. >>>More

18 answers2024-02-08

C is process-oriented.

C++ is object-oriented. >>>More

10 answers2024-02-08

It's a shame to ask your question, one is the development environment, the other is the language, what's the difference, you're laughing to death.