d0ts420
New Coder
For some reason strcpy function doesn't work :/
I'm writing on Virtual Studio Code with gcc as compiler.
Error:
[array of strings.c 2023-01-30 16:05:55.507]
,,array of strings.c: In function 'main':
array of strings.c:6:33: warning: excess elements in array initializer
6 | char cars[1][10] = {"Fiat", "Lancia", "Alfa Romeo"};
| ^~~~~~~~
array of strings.c:6:33: note: (near initialization for 'cars')
array of strings.c:6:43: warning: excess elements in array initializer
6 | char cars[1][10] = {"Fiat", "Lancia", "Alfa Romeo"};
| ^~~~~~~~~~~~
array of strings.c:6:43: note: (near initialization for 'cars')
array of strings.c:8:20: error: assignment to expression with array type
8 | strcpy(cars[0] = "Tesla");
| ^
array of strings.c:8:5: error: too few arguments to function 'strcpy'
8 | strcpy(cars[0] = "Tesla");
| ^~~~~~
In file included from array of strings.c:2:
C:/msys64/mingw64/include/string.h:61:18: note: declared here
61 | char * __cdecl strcpy(char * __restrict__ _Dest,const char * __restrict__ _Source);
| ^~~~~~
array of strings.c:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
10 | for (int i = 0; i < sizeof(cars)/sizeof(cars[0]); i++)
|
I'm writing on Virtual Studio Code with gcc as compiler.
I'm writing on Virtual Studio Code with gcc as compiler.
C:
#include <stdio.h>
#include <string.h>
int main(){
char cars[1][10] = {"Fiat", "Lancia", "Alfa Romeo"};
strcpy(cars[0] = "Tesla");
for (int i = 0; i < sizeof(cars)/sizeof(cars[0]); i++)
{
printf("%s\n", cars[i]);
}
return 0;
}
Error:
[array of strings.c 2023-01-30 16:05:55.507]
,,array of strings.c: In function 'main':
array of strings.c:6:33: warning: excess elements in array initializer
6 | char cars[1][10] = {"Fiat", "Lancia", "Alfa Romeo"};
| ^~~~~~~~
array of strings.c:6:33: note: (near initialization for 'cars')
array of strings.c:6:43: warning: excess elements in array initializer
6 | char cars[1][10] = {"Fiat", "Lancia", "Alfa Romeo"};
| ^~~~~~~~~~~~
array of strings.c:6:43: note: (near initialization for 'cars')
array of strings.c:8:20: error: assignment to expression with array type
8 | strcpy(cars[0] = "Tesla");
| ^
array of strings.c:8:5: error: too few arguments to function 'strcpy'
8 | strcpy(cars[0] = "Tesla");
| ^~~~~~
In file included from array of strings.c:2:
C:/msys64/mingw64/include/string.h:61:18: note: declared here
61 | char * __cdecl strcpy(char * __restrict__ _Dest,const char * __restrict__ _Source);
| ^~~~~~
array of strings.c:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
10 | for (int i = 0; i < sizeof(cars)/sizeof(cars[0]); i++)
|
I'm writing on Virtual Studio Code with gcc as compiler.