All Questions
14,279 questions
0
votes
3
answers
111
views
Creating an array of string pointers
I've reviewed many of the previous entries for this, but can't figure out why my (seemingly simple) construct doesn't work:
I want to create an array of pointers to previously-defined strings (char *)....
3
votes
2
answers
122
views
Inserting substring into string by pointer not working
I am currently trying to use C to write a function that inserts a substring into a string given the string, substring, and the position the substring is to be inserted. I am trying to manipulate the ...
1
vote
2
answers
77
views
How can i write this strcat function without getting exit code 139 and segfault? [duplicate]
I'm trying to write the following c code in order to make my own mystrcat() function (similar to the strcat() found in <string.h>) that concatenates 2 strings together.
When I run the following ...
0
votes
2
answers
67
views
C strlen() returns the wrong String length (character count) when using umlauts [duplicate]
I'm working on a C program, which takes an input in form of a parameter and then needs the length of the string to continue its work.
Unfortunately I'm facing a massive issue in form of a wrong ...
1
vote
0
answers
42
views
How to Handle Empty Fields When Parsing a CSV File in C [duplicate]
I am working on a program in C to parse data from a CSV file. The structure of my CSV file includes fields that may be empty, and I need to handle these cases properly. Here's an example of a CSV row:
...
1
vote
1
answer
68
views
String data from fgets is lost when using printf [duplicate]
I am new to C programming, and right now doing my first assignment in a C course.
I have noticed an unusual behavior when using a string in my code.
I am currently writing a simple string encoder, our ...
0
votes
0
answers
42
views
Why does my programm immediately input a blank space as Player1's name? [duplicate]
#include <stdio.h>
#include <string.h>
#include <time.h>
int playernumber();
struct Player
{
char name[20];
int score;
};
int main()
{
int num = playernumber();
...
1
vote
3
answers
118
views
How to check if a string contains one of a few key words in C
I'm pretty new to C but I'm experienced in python,
I'm trying to check whether an input string contains a certain word in it
for a example a mood checker
char str[20];
printf("How are you ...
0
votes
1
answer
94
views
C Thread Access Global Variable
So, I've been working on a socket messaging project on my free time, and I have not been able to get past the problem of the user's input erasing every time a new message is printed. I'm trying to ...
3
votes
2
answers
103
views
Seg fault on string array items after tokenizing in external function
I am trying to build a runtime command line tool and don't get why I get a segmentation fault when I try to tokenize the string input by the user.
In the str_utils.c file, the expression printf("...
2
votes
2
answers
86
views
Logic error of string input and output in C
I used Visual Studio.
The purpose of this code is to print the value that comes out when the received character arrangement is read vertically.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
...
0
votes
2
answers
115
views
Practice to use memcpy or strncpy to copies the string into memory
I am writing a piece of simple practice to compare the usage of between memcpy or strncpy. I see that I can do this string copy using either of these two functions:
char * strncpy ( char * destination,...
1
vote
0
answers
95
views
Segmentation fault due to SIGBUS [closed]
I have written a code, to reverse the words in a string, and it works for some test cases. But the problem is for remaining cases, it returns segmentation fault. When I'm checking for errors, I found ...
-2
votes
2
answers
112
views
Why can’t I use strtok directly on a string in C, and why do I need to copy it first? [duplicate]
I don't understand why I can't directly strtok(argv[1], ";")
(would there be a difference if the argv[1] is indeed an input from terminal with argv[1] is actually a list on heap?)
char *...
2
votes
2
answers
141
views
Generic QuickSort implementation struggles with a lot of strings
I made this quicksort implementation in C for uni that is supposed to be able to receive any type of array and sort it. For a stress test I was provided a records.csv file with 20 million lines ...
1
vote
1
answer
103
views
Providing strings for functions without quotes in C
So, I know this is not the best way to start a question-- I am guessing the answer already is 'no'.
But I will give it a shot anyways in case someone happens to know some 'black magic' that could be ...
2
votes
3
answers
131
views
converting hexadecimal string to decimal integer and vice-versa
Here the hexadecimal system is a bit different where A, B .... F are replaced by U-Z.
#include<stdio.h>
int main() {
// Write your program logic here. This line is a comment, you can leave ...
1
vote
1
answer
85
views
"Palindrome recursive function" detects palindromes right but doesn't behave as expected [duplicate]
I made a recursive function in C that prints whather entered string is palindrome or not.
It gives correct answers,but left and right pointers have weird values,and printf prints 4 times for string &...
0
votes
1
answer
100
views
How do I append to a string in C and write that modification back to the original string?
It is my first day writing programs in C and am confused as to why this code does not work. I have programmed before in C#.
Essentially, I am trying to initialise an empty string called onesString and ...
-1
votes
3
answers
121
views
Why is there a disparity b/w array of chars and string in C?
I noticed that if you define a string in C you need to take into consideration the nul terminator, which made intuitive sense that the computer need someway to check that the string has hit its end.
...
0
votes
2
answers
102
views
why printf can not print string of a pointer?
I write this program for print content of a string in c language.
but dont print string!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define GROW_BY 10
int main(){
...
0
votes
0
answers
66
views
What's the point with declaring a string with * or []? [duplicate]
I cannot understand the point with * and [] cause when reading courses on the internet, I come across things such like :
This only applies to character strings (i.e. the char* type, which can also be ...
0
votes
1
answer
121
views
Why is atoi() working as expected here, but when I use atol(), it returns 0 and modifies the input string to be empty ("")?
Edit: I am realizing that staging ground comment history is no longer visible when a post goes public: so I'll clarify a few points here. This function works fine when called directly from main(), but ...
0
votes
2
answers
139
views
Using memcmp() to compare signed bytes [closed]
I am trying to make a flexible mergesort function for primitive data types like char, byte, int, long etc, where the fucntion can take an array of any type and sort it by dividing it based on the ...
1
vote
0
answers
89
views
Trying to pass a string from one file to another, but failing
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *Arquivo, *Arquivo2;
char SerPassado[100], str[100];
// Open Archive.txt for ...
0
votes
1
answer
70
views
(the letter) k is the same as f for some reason [closed]
input is a string and well...when input[0] is 'k', its apparently the same as 'f'? like clearly it should be false and not output "f detected" right? k seems to have a value of 107 and f ...
1
vote
2
answers
114
views
String manipulation and conversion
For an exercise, I can take two integers or two strings. If I want integers as input, I need to convert them to strings or if I take strings as input, I need to convert the strings to integers. When ...
1
vote
1
answer
55
views
How to use zeromq to send a string with variable length?
I am new to zeromq and I want to use zeromq to send a self-defined struct. The struct is filled inside a C language project, and I use this struct to collect some log info from the C project. Then I ...
3
votes
3
answers
177
views
Is it possible to initialise parts of a string at compile time?
I'm trying to optimize some of my string initialization and concatenation to avoid using sprintf when it isn't required. I have a string that looks something like the following:
int n = 10;
char ...
1
vote
1
answer
59
views
Storing a string at some given address stored in a pointer
I have assigned a pointer ptr with a value of 0x8000_0000 which specifies some given address.
Now, I want to store "Hello World" string at this address location.
How can I do this ?
4
votes
3
answers
114
views
Why can't the token pasting operator (##) be used to concatenate two strings?
Why can't the token pasting operator be used to concatenate two strings?
For example;
#include <stdio.h>
#define MESSAGE "hello"##"world"
int main() {
printf(MESSAGE);
}
...
0
votes
0
answers
97
views
String arguments shifting between unrelated functions in Multi-Threaded C Program on RTEMS
I'm developing a multi-threaded C program to run on BeagleBone Black using RTEMS 6. I've encountered an issue where string arguments for a function are being used in the wrong position, leading to ...
0
votes
1
answer
59
views
CS50 - Pset 2 - Substitution - Issue with Check50 Not Detecting Output
I'm working on the CS50x 2024 Substitution problem set, and I'm encountering an issue with Check50 and Submit50 not detecting the output from my formatted string. I can see the correct output when I ...
2
votes
2
answers
146
views
Remove trailing whitespaces within [] with sscanf
I need to parse lines returned by utmpdump /var/log/wtmp. They are in this format:
[8] [13420] [ ] [ ] [pts/3 ] [ ] [0.0.0.0 ] [2024-07-22T11:18:29,836564+00:...
2
votes
1
answer
78
views
String allocated on the heap is corrupted when being accessed outside of the function C
I was trying to write some code in C to replace a substring in a given string following this tutorial. I managed to get it working, however one of the problems with the function is that it will result ...
0
votes
1
answer
70
views
Why is there random stuff in my string when printing its bytes?
I'm trying to see how format string bug works and tried to explore it by myself.
This is a simple program:
#include"stdio.h"
#include"string.h"
struct mystruct{
char buf[32];
...
-3
votes
1
answer
93
views
How do you use the "string" function is c [closed]
I was watching this CS50 course on computer science and it asked me to add the CS50.h header file but it wasn't available in my vs code as it wasn't cloud based like the cs50 one was
I wasn't really ...
0
votes
0
answers
56
views
Why doesn't char-pointer function parameter give seg fault error when modifying the string?
A character array declared as char str[] = "Gear"; can be modified but char* str = "Gear"; is a string literal that cannot be modified and gives seg fault error if we try to change ...
0
votes
0
answers
58
views
In C, There is no buffer overflow in strings [duplicate]
Whenever we store data more than the memory allocated to variable we got some unexpected results.But I declare a character array (name) with size 5 and get value from the user (greater than 5 ...
0
votes
0
answers
33
views
unable to take input of strings from user [duplicate]
I have to make an array of structure for cricketers presenting their name, age etc. and take input of each value from user . I am trying to get value of name from the user but my code editor keeps on ...
0
votes
2
answers
96
views
Error in assigning values to memory location with for loop [duplicate]
I have just entered the world of C programming, and I'm currently learning how to use malloc & free.
I've written a short excercise code to printf the string entered with scanf, and I am having ...
0
votes
3
answers
155
views
Is There a Better Way to Stringify Error Codes?
This is more of an aesthetic question than a purely functional one, but I want to know if there's any answer. See, I'm programming an error reporter for a project I've recently begun working on, and ...
3
votes
2
answers
86
views
fwscanf failing to read UTF-8 CSV file correctly in C
This program can only use libraries of the C standard.
I'm trying to read a UTF-8 encoded CSV file in C using fwscanf, but I'm encountering issues with the reading process. The file contains rows with ...
1
vote
0
answers
70
views
Handling Large Text Files with Pipes in C: Minimizing and Debugging a Word Frequency Counter
This program is a minimized version of a larger project that processes text files to generate CSV output with word frequencies. The full version works well for small to medium-sized files but ...
-1
votes
3
answers
126
views
C segfault question: if one of two inputs is null, return the other
I have a function that takes two strings and returns another string (if you must know, its my implementation of strjoin).
Now, I want to make it so that if one of the input strings is NULL, it will ...
0
votes
3
answers
141
views
Properties of strings
#include <stdio.h>
int main() {
char str[2];
printf("Enter anything ");
scanf("%s", str);
printf("%s", str);
}
What will become the output if ...
0
votes
0
answers
46
views
Why does the commented C code skip user input when called from another function? [duplicate]
The function with the problem
void login_starts()
{
while (TRUE)
{
memset(username, 0, USERNAME_MAX_SIZE*sizeof(char));
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
...
0
votes
1
answer
67
views
How not [?] to convert an enumerator into its corresponding string literal
Since I can't ask the author, I ask the community for suggestions: Why would you want to convert an enumerator into its corresponding string literal like done by the following example?
char* ...
3
votes
3
answers
104
views
How can I make char string array in C have dynamic size?
C language
I'm writing a function that relies later on on generating some text that has to hold the length of essentially: 115 letters minus the length of substring within <> from the original ...
0
votes
1
answer
42
views
MINGW x64 crash
I am writing some code and one of the libraries I am using required a newer version of MINGW, i am using the latest codeblocks and have the one bundled with CB and I downloaded MINGW 3.1 x64 and x32, ...