Questions tagged [c-strings]

A string in the programming language C is represented as a sequence of characters followed by a null terminator (represented as \0).

2715 questions
0
votes
2 answers

C - manipulating char * across functions

I have the below function which when called from main, returns a formatted filename (000.jpg) as a string when given an int. (I know we can use sprintf for this) Initialising char fn[8] = "000.jpg" in main works. When passed into function…
0
votes
0 answers

Printing arithmetic operator '+' from user input in C

I'm writing a program where the user can input a number with an arithmetic operator, and then I find out which arithmetic operator it is and print it. For ex- 123456+123456 --> Opertor present is: '+' I can't figure out how to identify the operator…
0
votes
2 answers

strtok weird behavior on tokenization

The below code gives unexpected behaviour. #include #include int main() { char s[] = "hello $"; char *t; t = strtok(s, "$$"); printf("%s", t); return 0; } Why does this output hello and not hello $?
user14675723
0
votes
1 answer

Same values with different pointers in a linked list?

Why does this code output the same name for all the nodes in the linked list? Program output Insert number of users : 4 Mike John Bob Alice Name : Alice @ Pointer :0x874ae0 Name : Alice @ Pointer :0x874b00 Name : Alice @ Pointer :0x874b20 Name :…
0
votes
1 answer

is there a reason why my isSubstring algorithm from GeeksforGeeks isn't working

Is there a reason why my isSubstring algorithm is not working? It's the same algorithm provided here: https://www.geeksforgeeks.org/check-string-substring-another/ but keeps returning 2 even though they it is the same substring in my eyes. int…
0
votes
2 answers

How to remove first 80 characters form a char array?

I've my char array, that has maximum size 1024. Anyway it contains a string of 200 characters. I want to remove exactly the first 80 characters from this 200 characters string. How can I do it? char my_array[1024]; for(int i = 80; i <…
user14677223
0
votes
2 answers

Finding the length of the last word input in C. At the while loop part, the if statement never reaches the else part, how to fix that?

Finding the length of the last word input in C. At the while loop part, the if statement never reaches the else part, how to fix that? The output for the input "Hello world" should be 5 #include #include int lsl(char s[]){ …
Eric Cao
  • 19
  • 3
0
votes
1 answer

Arbitrary character printed while manipulating string

I made the user defined function STR_LEN_BUFFER to mimic the behaviour of the strcpy, but instead of copying the null character '\0', it would continue printing spaces to fill in the resultant string, whose length is specified by MAX_LEN (set to 15…
Aloy
  • 13
  • 4
0
votes
2 answers

Copying a character from one string argument to another in C

The following program crashes without an error message after trying to replace the first character in s with t. The purpose of the program is to test if the two strings s and t are isomorphic: #include #include #include…
0
votes
1 answer

gcc C17 return from incompatible pointer type

char *funArr(char *s[]){ return s; } int main(void){ char *s[] = {"a","b"}; char *r = funArr(s); printf("%s",r[0]); } I can't get an array from a function correctly. I know what the problem is, but I don't know how to solve it.…
0
votes
4 answers

C program to count the occurrences of the letter "C" in a given string

I need help with my program. Sorry that my code is a mess. Any help is appreciated :)
user16387649
0
votes
3 answers

Can't call library function in user defined function

I am making a user defined function of strcmp() in c. #include #include int la,lb; // la and lb for length of 2 strings int scompare(char [],char []); int main() { char a[50],b[50]; // a and b are 2…
0
votes
0 answers

Confused about dereferencing operation in the disassembly of accessing a character in a string

I am having some trouble understanding how this operation works in assembly. I have a program I wrote and disassembled. In it, I access individual characters of a string and compare it to a test string. The important part of the code that I am…
CL40
  • 579
  • 1
  • 5
  • 12
0
votes
3 answers

what is the issue with this char reverse function?

so I wrote this code to reverse one of the names based on the user option the idea is to use another function to reverse and to use pointers but after trying all I could think of my code return the same name not changed the best I could do was…
Osama
  • 21
  • 5
0
votes
1 answer

Char array gets cleared after function gets() on C++

I'm trying to learn C++. Sometimes I get confused by C style strings and its functions. I've been using char var[1]; fflush(stdin); gets(var); to write a string into a char array. I don't know if thats the most efficient way but thats how I've been…
GZanotto
  • 31
  • 3
1 2 3
99
100