A string in the programming language C is represented as a sequence of characters followed by a null terminator (represented as \0).
Questions tagged [c-strings]
2715 questions
0
votes
3 answers
Cannot terminate cstring properly
I'm making a program that finds the most frequently inputted character and outputs it but a junk character takes over the output if it's less than the array value. I've tried putting null in multiple places. Putting it at the end, putting it at the…

Core
- 103
- 3
0
votes
0 answers
How to remove a word from a CString
I have the following CString which stores the path of a file how can I remove the last three chars of the Cstring AuthFile in order to change the file name
CString AuthFile = m_strFileName;
// Remove last three charters of CString…

Omar
- 164
- 10
0
votes
1 answer
C26492 Don't use `const_cast` to cast away const or volatile (type.3)
Here is an interesting discussion about not using const_cast where you are encouraged to use mutable.
Here is my code:
MENUITEMINFO sInfo{};
sInfo.cbSize = sizeof(MENUITEMINFO);
sInfo.fMask = MIIM_STRING;
sInfo.dwTypeData =…

Andrew Truckle
- 17,769
- 16
- 66
- 164
0
votes
2 answers
How to count how many word in string?
I want to know how to count how many words are in a string.
I use strstr to compare and it works but only works for one time
like this
char buff = "This is a real-life, or this is just fantasy";
char op = "is";
if (strstr(buff,op)){
…

Jack Savage
- 35
- 6
0
votes
2 answers
Why do addresses in array of char type pointers wsklan[0] and wsklan[0][0] differ?
Might be a silly question for you, and I couldn't find a good question for that, but the thing is - I don't understand and I'm asking you to explain that concept to me so I can understand, I would be really grateful.
So, the thing is - I was…

todovvox
- 170
- 10
0
votes
0 answers
Segmentation fault printing c-style string in for-loop
I encountered a segmentation fault when trying to print an element of an array of c-style strings (at the final iteration i=3). However, I am able to print the same element outside the for-loop.
char* pipe_segments[2];
pipe_segments[0] =…

qjk
- 21
- 1
0
votes
1 answer
I get an error when I initialize a string in a structure
I want to initialize a string with every char of it '\0'.(Because I will use gets() later, the first char being not '\0' is OK.)
So I use assign the string with "a".
Here is my code:
typedef struct node
{
char name[12] = "a";
struct node*…

Mike
- 5
- 3
0
votes
0 answers
Is it ok to terminate a string with two zeros?
I want to read a string with fread() from a file. It seems to me that fread() does not zero terminate a string on its own as I did not find any evidence in the documentation.
On all trials I did with fread() the strings were in fact zero terminated…

notAuser
- 31
- 3
0
votes
2 answers
Can't sort array in alphabetical order
I'm trying to make a program that simulates the ls command and then sorts the files in case insensitive alphabetical order. So far, all of the file names go into the words array, but when I try to compile, there is a problem.
#include…

Vearaa
- 25
- 5
0
votes
1 answer
Calling a void function?
I'm trying to write a program that can recognize a palindrome.
I've made a function for recognizing if it is a palindrome and used it in main successfully.
However, I also want to remove any spaces or numbers or special characters as those could…

notmenotyou
- 13
- 3
0
votes
0 answers
How do I maintainably store an array of c/c++ strings on the stack so it can be passed
The code I'm working on is largely C++ but calls out using c system calls because unix. In C++ a string literal is a const char[], as far as I know because they are stored in the text segment and you don't want to modify them. If I'm going to be…

davolfman
- 266
- 1
- 9
0
votes
1 answer
reversing an array of strings in c
So I'm trying to reverse an array of strings. The code is working but the issues are:
After the last input I have to enter an extra char (any char will do) and press enter in order for the code to execute.
That it prints 2 random char or ?? before…

Balou
- 21
- 7
0
votes
1 answer
C code to out yes if string contains all numbers, and no if it does contain something other than numbers
#include
#include
#include
int main(void) {
char input[50];
int i, hello = 0; // Wish to out Yes if "9999" is input. But why does it not happen?
scanf("%s", input);
for (i = 0; i

Cyrus Gomes
- 9
- 3
0
votes
3 answers
Create a duplicate of a string but reversed in C
I am trying to create a duplicate of a string but reversed.
I am able to strcpy each char and print them individually but I get nothing when I print the entire duplicate string.
#include
#include
#include
int …

Balou
- 21
- 7
0
votes
1 answer
not able to read a file by repetitive use of fgets
In this code, I am trying to read data from the file (30 characters in each line) with content:
hello world! Learning to code!
123456789123456789123456789123
The code used to read this file is:
#include
#include
int…

Agrudge Amicus
- 1,033
- 7
- 19