Function CpyWithoutPoints returns a pointer to an array of char (string), I can not figure out how to get the string itself.

 char tempName[30]; *tempName = CpyWithoutPoints(&str[0]); printf("%s ", tempName); - выводит какой то мусор и в конце нужную строку 
  • Try to declare like this: char * tempName; - Vladimir Martyanov
  • one
    If you want tempName[] to get a copy of the data in this array, the pointer to which is returned by CpyWithoutPoints() , then just copy them to the array - strcpy(tempName, CpyWithoutPoints(&str[0])); / The very title of the question is simply terrible, it seems to indicate a complete misunderstanding of the essence of arrays and pointers. Obviously due to problems with basic knowledge of the computer device. - avp

1 answer 1

In C, a string is nothing but a pointer to its first element. Constructions like char tempName[30]; declares an array of characters that is compatible with the pointer to the starting character, and therefore can be treated as a string.

In addition, the lines are not copied so simply, with = only the pointers themselves are copied, but not the contents of the line.

In order to copy the content, you need to use functions like strcpy . But in your example it is not necessary, because you already have a string!

Try to get rid of the selection of the tempName array.

 char* tempName = CpyWithoutPoints(&str[0]); printf("%s ", tempName);