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
2 answers
C function for maniplulating string
I have written this exercise which should remove any chars in the first argument string which appear in the second string. But the result is a segmentation fault for the arguments below. Can any one explain to me what am I missing?
#include…

Student
- 708
- 4
- 11
0
votes
2 answers
regexec and regcomp more efficient than doing strncmp myself?
I have a string like this:
I am down in the town seeing a crown="larry" with a cherry="red"
I want to write a program that asks user what she wants. If she requests the string that should have "larry" as crown and "red" cherry, I need to return the…

hari
- 9,439
- 27
- 76
- 110
0
votes
2 answers
why my cpp code can't run?(about char*[])
this is my code
the error is Segmentation fault,and i can't understand why
#include
#include
#include
#include
using namespace std;
int main(int argc, char* argv[])
{
char* szword[100];
int i = 0;
…

wanxin
- 21
- 4
0
votes
3 answers
How can I do an `if` check if the typed word is equal to some word in a string list in C?
How can I do an if check if the typed word is equal to some word in a string list in C?
Example:
#include
int main(){
char input[20];
char* strings[] = {"apple","banana"};
printf("try to hit one of my favorite fruits:\n");
scanf("%s",…
0
votes
0 answers
Getting segmentation fault when reading a string in array of strings
I am working on implementing the Shunting Yard algorithm for a calculator project I am working on in C, and I am getting output I do not understand. My version of the algorithm is meant to take in an array of strings (the various tokens of the math…

nickhealy
- 43
- 7
0
votes
1 answer
strcpy() unusual behaviour in C
so I decided to test out how strcpy() works and while reading the Linux Programmer's Manual. I came across the definition of strcpy
The strings may not overlap, and the destination string dest must be
large enough to receive the copy.
So from…

Areen
- 21
- 4
0
votes
3 answers
Advice/help/better solution for checking whether a given string can be a valid IP address or not
Honestly, I think the code which I've written is trash and I don't think it's the best way to solve the problem. I need a few suggestions or improvements to solve this problem. I'm still new to coding. Appreciate it if you can give some tips on how…

josh_3501
- 15
- 2
0
votes
2 answers
Concatenating two strings but getting null. please pont me error in this
I am trying to copy two strings to a new pointer. this is to concatenate string pointer with sub pointer. Trying to make the output in new pointer str .what is wrong in this?
void addsubstring( char* string, char* sub)
{
//int m =…
user16199289
0
votes
3 answers
pointer string not returning expected output
#include
void revstr(char str[])
{
char temp;
int size = 0;
while(*str != '\0'){
size++;
str++;
}
for (int i = 0; i < size/2; i++)
{
…

nabeel khan
- 5
- 4
0
votes
1 answer
Passing char* to atoi
Here's the scenrio -
#include
#include
#include
int main()
{
uint8_t backoff;
char* value = "300000";
backoff=atoi(value);
…

Anshika Verma
- 45
- 6
0
votes
2 answers
basic resursion que of string
i have some set of rules to create a string in a char array
a. The string begins with an 'a'
b. Each 'a' is followed by nothing or an 'a' or "bb"
c. Each "bb" is followed by nothing or an 'a'
my code is:-
bool checkAB(char input[]) {
…

Kishan Raj
- 3
- 1
0
votes
1 answer
Is there any alternative for 'substr()'?
char patern[]="AGAAGAG";
int n = strlen(patern);
int pat[n];
for (int i = 0; i < n; i++)
{
int j = 0;
while(j <= i )
{
if (patern.substr(0, j) == patern.substr(i-j+1, j))
{
pat[i] = j;
}
j++;
…

zead seam
- 31
- 5
0
votes
1 answer
I have some problems with fopen() for c-string
I have a file name stored as c-string. I need to open the file and count lines in it.
#include
#include
#include
using namespace std;
int main() {
char str[] = "myfile.txt";
FILE* file = fopen(str, "r");
int…

Fenix FVE
- 53
- 4
0
votes
3 answers
Using strtok to find pair of token
I am solving this homework problem: Find a pair of adjacent words in the text, such that both words begin in the same letter.
I understand that I need to use strtok function to solve this problem.
#include
#include
#include…

Кирилл Боровой
- 449
- 1
- 4
- 14
0
votes
2 answers
Why am i getting a segmentation fault using scanf? I've initialized and set memory size, but still getting seg fault
Noob question, probably. I've looked through other answers, and I've tried what they've done. But I'm still getting the error every time. This is the first snippet from my caesar cipher program.
#include
#include
#include…

morr0564
- 53
- 7