All Questions
2,051 questions
4
votes
3
answers
138
views
remove a character by using conditional statement
recently just practiced the problem 67 in Leetcode This problem is like you would be given two binary string, and you have to calculate the sum of these two binary string and return the result.For ...
4
votes
3
answers
141
views
If I am using UTF-8 strings is it risky to use standard string handling that assumes null termination?
From what I understand it is very rare for UTF-8 strings to have embedded NULLs, however there is the case that a person can put a NULL into a Unicode string explicitly with "X\0Y" or ...
3
votes
4
answers
166
views
Change pointer adress inside function in C
I'm trying to make a program that deletes extra white spaces from a string. It should keep one space but delete any extra.
I wrote this code, which works up until the point I have to change the passed ...
1
vote
2
answers
62
views
Line extraction in a char
Hi i'm trying to write a recursive function to extract each line of a string. I don't know why it doesn't work i spent 2 hours trying to find the issue.
#include <string.h>
#include <stdlib.h&...
1
vote
2
answers
99
views
How to debug this substring matching code?
I am a beginner in C programming, and this is a string matching code I wrote. It aims to find the positions where the substring t appears in the string s and print them. The use of pointers is ...
4
votes
2
answers
167
views
Why does fgets() require a maximum size of user input? Is it because it does not have the "restrict to first space" property of scanf()?
This is fgets()'s official prototype:
char *fgets(char *str, int n, FILE *stream);
Why specify the size (n) ? Is it to prevent buffer overflow of some sort? Or is it just a design flaw?
I would think ...
1
vote
1
answer
83
views
How to compare an array with a char using if in C?
I ask for your help. I need to compare an array of tokens with a char using the if statement. But in the array I also have a string, the code is this:
char bho(char** Token){
char* token = (char*)...
2
votes
3
answers
190
views
Why is the strlen here equal to 25?
Just so I can confirm if what I think is going on is really going on. The following code prints out 25 when I give it the (26 letter) alphabet as an input, is it because fgets always automatically ...
-2
votes
3
answers
122
views
Insert Sort with Strings in C [closed]
I'm trying to make a insert sort with strings. That's my code below.
#include <stdio.h>
#include <string.h>
#define MAXLINES 5
#define MAXLINEC 1000
int
main(void)
{
char lines[...
0
votes
1
answer
111
views
Adding elements into a char array
I've been trying to make a function in C that takes a string as the input and then prints out a version of that string that only contains alpha characters.
#include <string.h>
#include <ctype....
1
vote
1
answer
85
views
C pointers: Function returns a pointer defined in its body [duplicate]
I'm learning C using the book C Programming: A Modern
Approach and I have some doubts about the use of pointers
and referencing an out-of-scope variables. I've put together three examples to
...
1
vote
3
answers
104
views
Does s conversion specifier specify direction / order in which characters are written?
Does s conversion specifier specify direction / order in which characters are written?
N3220 working draft, 7.23.6p8 (emphasis added):
s If no l length modifier is present, the argument shall be a ...
-1
votes
2
answers
88
views
char *array[200] sorting program doesn't read words
The program is expected to sort and display a list of words from a array whose elements are pointers to char. I use malloc to alocate space to each element and use a read_line function to store in the ...
1
vote
2
answers
8k
views
Unexpected behaviour while swapping strings in C
I am a beginner to programming and today I was trying to swap two strings with somewhat of a raw , brute force logic . But I stumbled upon this behaviour :
My code :
#include <stdio.h>
#include ...
1
vote
1
answer
127
views
Finding possible permutations of a word
again. I've written a code on finding all possible combinations on a word and my code works but very limited times (i.e) it prints the string with "a" being only swapped (my I/P is abcd) but ...