there is a pointer *N ; N="it's a good weather today"; char A[100]; How to assign the value of A N or just how to display N on the console?
- oneShow me an example code, but nothing is clear - Abyx
|
1 answer
If you have a pointer that addresses a string literal
char *N; N = "it's a good weather today"; and character array
char A[100]; To copy a string literal into a character array, you should use the standard C function strcpy , declared in the header of <string.h> . For example,
#include <string.h> //... strcpy( A, N ); provided that the array is large enough to hold a string literal in it. Otherwise, use the strncpy function.
#include <string.h> //... strncpy( A, N, sizeof( A ) ); A[sizeof( A ) - 1] = '\0'; After that, you can output a string to the console, such as
puts( A ); or
printf( "%s\n", A ); |