How to take a string in a specified position in the C language

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

    You can use the strstr function:

    Function name: strstr

    Function: Find the first occurrence of a specified string in a string: char *strstr(char *str1, char *str2);

    Example: include

    #include

    int main(void)

  2. Anonymous users2024-02-14

    There shouldn't be a library function specifically for this, so it's good to make it up yourself, it's not complicated.

  3. Anonymous users2024-02-13

    No way, right?

    You have to write your own functions to do this.

  4. Anonymous users2024-02-12

    Using some functions of string to implement, the algorithm is simple and clear, and it has been verified that you can directly copy and paste.

    #include

    #include

    #include

    #include

    using namespace std;

    void main()

  5. Anonymous users2024-02-11

    Examples are as follows:

    Direct compilation, arbitrary input strings and numbers in the program output result, the program execution result is shown in the following figure:

  6. Anonymous users2024-02-10

    You can use the strncpy() function.

    #include

    char sub[20];

    strncpy(sub,string+12,13) *copies the 13 digits in string starting with string[12] into sub*

  7. Anonymous users2024-02-09

    If there is a special function for extracting a string of a specified length: strncpy(*s1,*s2,n);

    If you extract m characters starting from n in a string, the procedure is as follows:

    #include

    #include

    void main()

    elseprintf("The length is out of range! ");

    elseprintf("The starting position is out of range! ");

  8. Anonymous users2024-02-08

    If you want to divide a piece of data into chunks in the C language, you can store it in chunks when reading the data, instead of reading it as a whole and then chunking it.

    If the data is imported in other ways, it can only be stored on the hard disk, then read into memory, and then read in chunks by moving the file pointer.

    Because the data store is stored in the whole block of memory, the memory (i.e., the data) cannot be directly chunked, and memcpy can only get the first part of the data.

  9. Anonymous users2024-02-07

    Use a string to copy another string t, scan the string t from beginning to end, write string s for non-numeric characters as is, write a $ sign for numeric characters and then write the numeric character, and finally, add an end sign to the end of the s string. Use this method to sacrifice space, gain time.

    #include

    int fun(char *s)

    For non-numeric characters, the string s* is written as-is

    elses[j++]=t[i];

    s[j]='\0';* add the end flag at the end of the string S * return 0;

    int main()

  10. Anonymous users2024-02-06

    Design Process:

    Define two strings: s2, s2, and the character k

    Enter any character k in the two strings s1, s2 and s1 to iterate through s1 to find the specified character k, record the current position starting from k character, and move the rest of the data back by the length of s2.

    Copy S2 to the location where K is located.

    Output s1. ** Below:

    #include

    #include

    void main()

    pos=i;Make a note of where you want to insert it.

    len=strlen(s2);get the length of s2 for( i=strlen(s1); i>=pos;i-- Move the string backward.

    Insert data. printf("%s", s1 );Output string}

  11. Anonymous users2024-02-05

    Nonsense on the first floor, I told you to assign the s1 definition array, assign the initial value of the s2 definition array, and shift the array s3 containing s1 and s2, and the output of s3 is OK.

  12. Anonymous users2024-02-04

    put"beijing"into an array of characters.

    put"123"into another character array.

    Before applying for a large enough array space, assign these two character values according to the following table.

  13. Anonymous users2024-02-03

    Maybe it's easier to implement it with a linked list, here's the program with an array:

    #include

    #include

    main()

    n=strlen(b);

    k=m;for(j=m+n;j>i;j--,k--)a[j]=a[k];

    for(j=i,k=0;jprintf("%s",a);}

  14. Anonymous users2024-02-02

    Stored in a char array (C C++ is supported).

    char str="hello" ;

    int i;

    for( i=0;str[i];i++ printf("%c", str[i] ) refers to a character as an array: str[i].

    for( i=0;*(str+i);i++ printf("%c", *str+i) ) Refer to a character as a pointer: *(str+i).

    Stored in string (C++ only).

    string str="abcde";

    for(string::iterator iter = ; iter!=;iter++) uses iterators.

    cout<<*iter<

  15. Anonymous users2024-02-01

    The mistake is that when you judge the first non-@ character, it already outputs no character @ to exit the loop, so it won't detect @. Just change it to the following:

    #include

    #include

    intmain()

  16. Anonymous users2024-01-31

    Remember to prefix it with include

    str[i];(i is where you want the character to be) include

    #include

    int main(void)

  17. Anonymous users2024-01-30

    #include

    define n x and change x to 1 if you want the first few

    int main()

  18. Anonymous users2024-01-29

    Any characters?

    Random? Specify a location?

  19. Anonymous users2024-01-28

    You can change the size of the array to suit your possible input situation.

    #include

    int main(){char str[200];Suppose you enter a 1-line string with a length of less than 200 char s[20][16]; Suppose there are about 20 comma-separated sections.

    Each length should not exceed 16 characters and double d; Assuming that the number of data does not exceed 20 int i,j=0,l,n=0; fgets(str,200,stdin)。

    Read in a line string with a newline character l = strlen(str).

  20. Anonymous users2024-01-27

    You can use the strstr function:

    Function name: strstr

    Function: Find the first occurrence of a specified string in a string: char *strstr(char *str1, char *str2);

    Example: include

    #include

    int main(void)

Related questions
6 answers2024-08-05

You can add a 0 to the end of the array, but you can't have a 0 in the middle. Then change it to something like this: >>>More

11 answers2024-08-05

Valid variable names for the C language:

First, it can only contain numbers, letters, and underscores. >>>More

6 answers2024-08-05

It seems that you don't know much about structs and struct pointers, the data array is a struct array that you define, it consists of two knot body elements, and each struct element contains two members x and y, the first element is 1 and 10, the second element is 2 and 20, the struct pointer p you defined starts to point to the first element of the array data, p points to the second element of the data array, and the pointer p can manipulate the two members x and y >>>More

15 answers2024-08-05

A fixed point number is a representation of a number employed in computers. The decimal point of the number involved in the operation is fixed. Fixed-point numbers are further divided into fixed-point integers and fixed-point decimals. >>>More

8 answers2024-08-05

The semicolon is the sign of the end of the statement, but the semicolon is not used after the loop, if, and subfunctions such as long long a (int b), and everything else is used, but two semicolons cannot be added, although it will not cause an error, but it may affect the result.