You’re saying you have this:
char array[20]; char string[100]; array[0]='1'; array[1]='7'; array[2]='8'; array[3]='.'; array[4]='9';
And you’d like to have this:
string[0]= "178.9"; // where it was stored 178.9 ....in position [0]
You can’t have that. A char holds 1 character. That’s it. A “string” in C is an array of characters followed by a sentinel character (NULL terminator).
Now if you want to copy the first x characters out of array
to string
you can do that with memcpy()
:
memcpy(string, array, x); string[x] = '\0';
Related Posts:
- How do I determine the size of my array in C?
- char *array and char array[]
- How do I create an array of strings in C?
- “Expected expression before ‘ { ‘ token”
- C pointers and arrays: [Warning] assignment makes pointer from integer without a cast
- How to print the array?
- How do you make an array of structs in C?
- How do I create an array of strings in C?
- Return char[]/string from a function [duplicate]
- Why am I getting “array initializer must be an initializer list or string literal”?
- Using Dynamic Memory allocation for arrays
- Finding the length of a Character Array in C
- Return char[]/string from a function
- How to print a char array in C through printf?
- How to clear all the elements of array in C?
- Zero an array in C code
- Passing an array by reference in C?
- Excess elements in char array initializer error
- I’m getting “Invalid Initializer”, what am I doing wrong?
- Iterate through a C array
- What is the difference between char array and char pointer in C?
- The difference between char * and char[] [duplicate]
- The difference between n++ and ++n at the end of a while loop? (ANSI C)
- Working on code to calculate cosine with factorial sum
- warning: implicit declaration of function
- What exactly is the difference between “pass by reference” in C and in C++?
- What does “collect2: error: ld returned 1 exit status” mean?
- How to convert an int to string in C?
- Floating point exception (core dumped)
- what is the difference between uint16_t and unsigned short int incase of 64 bit processor?
- Correct format specifier for double in printf
- How to convert a string to integer in C?
- What is the behavior of integer division?
- Awesomium sdk download
- Bad File Descriptor with Linux Socket write() Bad File Descriptor C
- What is the difference between char s[] and char *s?
- warning: assignment makes integer from pointer without a cast
- munmap_chunk(): invalid pointer
- printf() formatting for hexadecimal
- The importance of c enumeration (typedef enum) [duplicate]
- Error “initializer element is not constant” when trying to initialize variable with const
- Cannot assign requested address – possible causes?
- need help understanding the movzbl call in this function
- What is the difference between read and pread in unix?
- What does “control reaches end of non-void function” mean?
- connect Error: “No route to host”
- warning: implicit declaration of function
- C dynamically growing array
- How to replicate vector in c?
- Why do I get an assertion failure?
- Difference between int32, int, int32_t, int8 and int8_t
- C compile error: “Variable-sized object may not be initialized”
- What does WEXITSTATUS(status) return?
- Difference between a Structure and a Union
- lvalue required as left operand of assignment
- how to convert negative hexadecimal to decimal
- Why am I getting “undefined reference to sqrt” error even though I inclu de math.h header?
- How to initialize a struct in accordance with C programming language standards
- Expression preceding parentheses?
- Linux equivalent of I_PUSH
- Understanding INADDR_ANY for socket programming
- The Definitive C Book Guide and List[
- When is it a good idea to use strdup (vs malloc / strcpy)
- return makes integer from pointer without a cast [-Wint-conversion] return candidate
- expression must have integral type
- Math constant PI value in C
- Why is %c used in C?
- What is Innermost loop in imperfectly nested loops?
- What’s wrong with my code? What is argv[1]?
- What can cause a “Resource temporarily unavailable” on sock send() command
- How to solve error: expected identifier or ‘(‘
- Split string with delimiters in C
- How to pause in C?
- (.text+0x20): undefined reference to `main’ and undefined reference to function
- Why am I getting this error: “data definition has no type or storage class”?
- How can one print a size_t variable portably using the printf family?
- How to make sense of modulo in c
- Error: initializer element is not computable at load time
- Uninitialized value was created by a heap allocation
- Makefile:1: *** missing separator. Stop
- double free or corruption (!prev) error in c program
- xorl %eax – Instruction set architecture in IA-32
- Excess elements of scalar initializer for pointer to array of ints
- Two or more data types in declaration specifiers error
- ‘sprintf’: double precision in C
- C printing bits
- PTHREAD_MUTEX_INITIALIZER vs pthread_mutex_init ( &mutex, param)
- How to concatenate string and int in C?
- execvp: bad address error
- How detect malloc failure?
- A Simple, 2d cross-platform graphics library for c or c++?
- Removing last character in C
- Difference between char *argv[] and char **argv for the second argument to main()
- Dereference void pointer
- Use of flag in c?
- Carriage return in C?
- Difference between “while” loop and “do while” loop
- Swapping 2 Bytes of Integer
- GDB no such file or directory
- variably modified array at file scope in C