Problems with defining strings in the C language

Updated on technology 2024-04-30
25 answers
  1. Anonymous users2024-02-08

    Do you mean to say that a is a value of 10 or does a literally mean 10?

    If we talk about the numeric value, send[0] =10; send[1] = 20 so the assignment will do.

    If you say it literally, you can only record a = 10, b = 20, c = 30, d = 40 and then make send, for example: sprintf(send,"%d%d%d%d", a, b, c, d);

  2. Anonymous users2024-02-07

    this topic. I didn't get it.

    Since it is a string, the content in send[30] is a string, and the content can be divided into char, but you can't assign a value to each char in it, because it is not a variable.

    This should use a linked list.

  3. Anonymous users2024-02-06

    Define a string send[30] first, and then define the character variables a, b, and c; Use the strcat(send,a) function to connect them.

  4. Anonymous users2024-02-05

    You can take a look at the usage of the atoi function, which converts an integer to a string. For example, (int)2012 is converted to"2012"(characters).

  5. Anonymous users2024-02-04

    You want to write this integer data as a string and put it in a string, right?

  6. Anonymous users2024-02-03

    It is recommended to use a macro definition. How to do it can be found on the Internet, and there are many articles that introduce macro definitions.

  7. Anonymous users2024-02-02

    I don't quite understand what you mean, please elaborate.

  8. Anonymous users2024-02-01

    Let's say you want to define a character: char a[20]="The string you want to write"。

    A string can be stored in the array as an initialization when defining an array of idiosyncratic characters, but cannot be directly assigned by an assignment expression. For example: char mark[10]; mark=''c program'';The assignment is not valid

    And the correct one: char word[20] = "dictionary".

    char name[ ]= “tommy”

    char c[10] = ;The last character '0' must be present for the string ending flag.

  9. Anonymous users2024-01-31

    It is to define an array of characters.

    e.g. char s[20];

    Note: Strings end with "0" and need to be at least 1 byte in addition to the length of the characters that can be displayed.

  10. Anonymous users2024-01-30

    1.BAI can be introduced

    Header file include

    string str = "hello"Initialize to hello2You can use the number du group to directly zhi

    Define an array. Define a static DAO dynamic.

    Static: version char c[10]; Set the array length to weighted 10 dynamic: int a = 10;

    char *c = new char[a];Customize the array length to the size of a, the size of a can be customized by entering.

  11. Anonymous users2024-01-29

    Header file to include

    string str="hello world!";

    Or use the character array char in c

  12. Anonymous users2024-01-28

    #include

    #include

    int main()

    for(int i = 0; i < 3; i ++

    Just run this program, tested it in VS2008. Pay attention to two places.

    #include

    namespace std;

    Don't include, it's a string library in C, and String is a C++ library, and the two have nothing to do with each other. The string in C++ is contained in the std namespace, so add a second sentence.

    c Language.

    C++ is the inheritance of the C language, which can not only carry out the process programming of the C language, but also carry out the object-based programming characterized by abstract data types, and can also carry out the object-oriented programming characterized by inheritance and polymorphism. C++ excels at object-oriented programming as well as process-based programming, so C++ is based on the size of the problem it can adapt to.

    C++ not only has the practical characteristics of efficient computer operation, but also strives to improve the programming quality of large-scale programs and the ability of programming languages to describe problems.

  13. Anonymous users2024-01-27

    You can define a string with an array of characters or a character pointer, or you can define a constant string with a macro definition.

    Let's take a look at each of them with examples:

    char str1 = "helloworld";A string is defined by an array of characters"helloworld", one character per memory cell in the array.

    char *str2 = "helloworld";Character pointers are used to define strings"helloworld", pointer str2 points to a storage string"helloworld"The first address of the contiguous address unit.

    #define str3 "helloworld";Strings are defined by macro definitions"helloworld", equivalent to str3="helloworld"

  14. Anonymous users2024-01-26

    To learn C language strings, enter a specified string and calculate the number of digits of the string.

  15. Anonymous users2024-01-25

    You can use arrays or pointers.

    Array: char s[80]="abcd";or char s[80]=; Note: Auto-add string end flag: 0*

    char s[80]=;

    pointer: char *s; char*s="abcd";

    C is a general-purpose computer programming language with a wide range of applications. C is designed to provide a programming language that can compile in a simple way, handle low-level memory, generate a small amount of machine code, and run without any runtime support.

    Although C provides many low-level processing functions, it still maintains a good cross-platform characteristic, and C programs written in a standard specification can be compiled on many computer platforms, including some embedded processors (microcontrollers or MCUs) and supercomputers.

    In the 80s of the twentieth century, in order to avoid the differences in the C language grammar used by various developers, the National Bureau of Standards of the United States formulated a complete set of international standard grammar for the C language, called ANSI C, as the original standard for the C language.

  16. Anonymous users2024-01-24

    1. In C language, use the keyword char to define character variables. char is used to define character variables in C or C++, occupies only one byte, and the value range is -128 +127 (-2 7 2 7-1).

    2. A string or string is a finite sequence of zero or more characters. It is generally denoted as s=a1a2an(n=0). It is a data-class companion that represents text in a programming language.

    3、=;Each string ends with a 0 (i.e., a value of 0), in other words, the first one is a few, and you can hold several strings with a maximum length of the second -1.

    4. There are no strings in the C language, only the array of characters is represented by chars[length]. length indicates how many characters you want the string to have. This is different from string in C++, where string can be directly assigned, such as strings; s=helloworld, but this is not the case in the character array area in C.

    5. In C language, char is used to define character type variables or character pointer cluster variables, such as "chara; The variable a is defined to be a character type, "char*a; Variable A is defined as a character pointer type.

  17. Anonymous users2024-01-23

    In the C language, the character char is used to represent the storage character, and there is no separate string type string in C++;

    Therefore, C uses an array of characters and a character pointer to implement the string function;

    The character array of c can only be assigned together when defined, and can only be assigned to individual elements one by one later;

    char string0[10];

    char string1="prison break";

    char string2[100]="michael scofield";

    Sentence 1 means that a string of length 10 is defined but not assigned, and sentence 2 indicates that an array of characters string1 is defined and initialized so that its length is automatically 13 (string "prison break"plus the number of characters in plus the ending'\0'), sentence 3 defines a character array with 100 elements string2, and initializes 17 elements ("michael scofield";Plus the ending'\0')。

    The C language itself does not set a type to define string variables, and the storage of strings depends entirely on character arrays, but character arrays are not equal to string variables. Store strings in a one-dimensional array of characters and specify them in characters'\0'as a string end flag.

  18. Anonymous users2024-01-22

    Both one-dimensional and two-dimensional are acceptable;

    The one-dimensional situation is as follows:

    1,char string0[10];

    2,char string1="prison break";

    3,char string2[100]="michael scofield";

    Sentence 1 means that a string of length 10 is defined, but no value is assigned, and sentence 2 means that an array of characters string1 is defined and initialized so that its length is automatically 13 (string "prison break"plus the number of characters in plus the ending'\0'), sentence 3 defines a character array with 100 elements string2, and initializes 17 elements ("michael scofield";Plus the ending'\0');

    The two-dimensional situation is as follows:

    1,char string3[6][30];

    2,char string3[6][30]=;

    This sentence indicates that there are 6 strings, each with a length of 30, and the initial value of each string is the same as "joy."","phosee","monses","chandele","ross","rather"corresponding;

  19. Anonymous users2024-01-21

    Strings can be defined by character arrays or character pointers, or by macro definitions for constant strings.

    Line definitions. Right of passage below.

    Let's take an example to illustrate each one:

    char str1 = "helloworld";A string is defined by an array of characters"helloworld", one character per memory cell in the array.

    char *str2 = "helloworld";Character pointers are used to define strings"helloworld", pointer str2 points to a storage string"helloworld"The first address of the contiguous address unit.

    #define str3 "helloworld";Strings are defined by macro definitions"helloworld", equivalent to str3="helloworld"

  20. Anonymous users2024-01-20

    C has a 0 ending in each string, and your b doesn't have a 0 at the end of the string, so everything in memory is displayed together.

    Add a b[t] after the end of your for loop

  21. Anonymous users2024-01-19

    Because the string is based on the'\0'Ha at the end, then the length of the string you define is 80 Ha, if it does not reach the specified length, the system will automatically add it, just like the effect of your program; Here's how to fix it:

    1.After copying, add at the end of the string'\0';

    2.Enter the length of the string you specify.

  22. Anonymous users2024-01-18

    There is one at the end of the string'\0'。strlen(string) only calculates the actual length, not the actual length'\0'.This results in your for loop not being replicated'\0', resulting in B not having an end sign, so there are so many "hot".

    Modification method: t=

    strlen(a)+1;

  23. Anonymous users2024-01-17

    for(i=0;i<=t;i++)

    This t only contains the total number of characters, not the final closing character, just pass it to b.

  24. Anonymous users2024-01-16

    Defined as an array of characters or string.

  25. Anonymous users2024-01-15

    The materials that need to be prepared are: computer and C language compiler.

    1. First of all, open the C language compiler and create a new initial. CPP file, for example:

    2. In the file, enter C language**:

    char a[10] = "hello";

    char b = "hello";

    char *c = "hello";

    printf("%s%s%s", a, b, c);

    3. The compiler runs the file, and at this time the string is defined by all 3 types.

    The method of success definition is output.

Related questions
6 answers2024-04-30

Use the ITOA function.

Prototype: extern char *itoa(int i); >>>More

4 answers2024-04-30

Just take a look at this one**.

Hope it helps. >>>More

3 answers2024-04-30

Strange indeed, the result of my experiment is that if the string variable is initialized first, the subscript can be used to read and write the string variable normally. >>>More

7 answers2024-04-30

Do it by your train of thought.

Method 1. string strnumber="200m"; >>>More

4 answers2024-04-30

<> output conforms to the example, hope

Source code: include >>>More