Skip to main content

All Questions

0 votes
4 answers
217 views

How to write a function in c that counts words

I had an exam yesterday in which one of the questions was about counting words in a given string. The definition of word would be a portion of a string that is divided by spaces and/or the beginning/...
nobody really's user avatar
0 votes
2 answers
75 views

Why does this char* comparison function return -1 when the two input strings are the same? Language: C

I made a function that is supposed to help me order strings in alphabetical order: it should return -1 if the first string comes before the second one, 0 if they are the same string and 1 if the first ...
Ugo Flickerman's user avatar
0 votes
1 answer
440 views

Swapping and copying two strings into one another without using strcpy() in C

this program is meant to take two strings and call a function that copies string 1 into string2, and vice versa, while fulfilling the following criteria: Uses pointers Uses only while loops does not ...
not_castillo's user avatar
-1 votes
2 answers
116 views

While(*x) without another condition

I'm learning about the "strcmp" function , It was concerning to me when looking in the syntax of the function prototype I noticed this "while(*x)" loop can someone please explain ...
Steve Bob's user avatar
1 vote
2 answers
6k views

heap-buffer-overflow for Leetcode strStr problem

The problem is for LeetCode's Implement strStr. I have a working solution when I compile and execute in my computer, it works fine, but when I try to run it with LeetCode it gives me some weird error. ...
altair00's user avatar
  • 174
1 vote
1 answer
749 views

Reading elements from a string in C

I am trying to print the first letter of a word at the position entered by the user. If there is a whitespace, then it will just stop searching. There is a warming message concerning funtion gets(). I ...
Maroon Racoon's user avatar
-1 votes
2 answers
61 views

What is this line of code achieving? What does the incrementation mean? [duplicate]

I understand that s and t are both pointers and they are being copied to one another but the incrementing part is confusing to me. void funct(char *s, char *t){ while( *s++ = *t++ ); }
Carsoncode's user avatar
0 votes
2 answers
86 views

Concat two strings through pointers not working

I made a function that concat string t to the end of string s, for my exercise I have to use pointers for this, so I did this way but its not working: #include <stdio.h> void strcat(char *s, ...
Carlos Henrique's user avatar
2 votes
4 answers
998 views

My strstr function works, but a program designed to test it says it doesn't

for school, I have to recreate the strstr function. I did, and I tested it as much as I could, and everything seems to work perfectly. I am still looking into it but after several hours of ...
Toyama70's user avatar
0 votes
2 answers
88 views

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* ...
user avatar
0 votes
5 answers
2k views

Can you explain what while(*++str1) and return (str1 - str2) does?

In this context, does the while loop work like a for loop? Also, what does the str1-str2 string subtraction result in? #include <stdio.h> int fun(char *str1) { char *str2 = str1; ...
CHINMAY's user avatar
  • 27
1 vote
3 answers
473 views

When does a while loop stop when it reads a string in C?

I'm trying to implement the strcpy function by myself. The original strcpy is part of the the string.h library. char *strcpy(char *dest, const char *src) { assert(dest != NULL && src != ...
NoobCoder's user avatar
  • 615
1 vote
5 answers
257 views

Why won't this C function return strings?

I've been messing with this really simple C function to return the contents of a text file as a string for quite a while now, but no matter what I do, it doesn't work. #include<stdio.h> char* ...
James Browning's user avatar
0 votes
2 answers
100 views

Can you help me find a problem with this basic C code

I'm solving some problems from a C programming book to brush up on Strings. I can't figure out why my solution is not working. Question asks to write a function named censor that modifies a string by ...
Manish's user avatar
  • 15