All Questions
233 questions
3
votes
1
answer
140
views
String split function in C
I'm trying to write a string splitting function in C, much resembling ones already available in other higher-level languages.
In order to save myself the hassle of constant memory (re-)allocation with ...
1
vote
3
answers
80
views
printf() is printing a character after the terminating character in C, how do I fix this?
I have a for loop in randomString() that puts a random character into the first x indexes of a string, where x < the string length. I then add a '\0' to the string and print it with printf() but it ...
2
votes
2
answers
701
views
Subscripted value is neither array nor pointer nor vector. Taking input of n strings using struct in C
The question states that I take input from the user to enter n number of names using structures in C. I have written the following code:
#include<stdio.h>
typedef struct employee{
int code; ...
-3
votes
1
answer
1k
views
According to C there is no function named strlwr(). What is wrong? [duplicate]
#include <stdio.h>
#include <string.h>
int main(){
char n[] = "NAME";
strlwr(n);
printf("%s", n);
return 0;
}
I just wanted to print lower case "...
1
vote
3
answers
101
views
Anything wrong spec-wise with this string comparison optimization?
Assuming no string less than 4 bytes is ever passed, is there anything wrong with this optimization? And yes it is a significant speedup on the machines I've tested it on when comparing mostly ...
0
votes
1
answer
74
views
C: Count how many letters are in the string and print the word reversed using functions
So I have managed to find whether a string is palindrome or not, But I can't seem to find how many letters are in the word given by the user and the word printed backward.
Also is there a way I can ...
0
votes
0
answers
61
views
Write a c program that asks for a string and tells the frequency of all characters in the word
How do I find the frequency of all the characters and not only one character (using functions and strings)?
Example input: aaaaabbccc
Expected output:
'a' : 5
'b' : 2
'c' : 3
#include <stdio.h>
...
0
votes
1
answer
767
views
How can I create multiple structs with different Strings using a Loop in C?
I'm doing an assignment where I have to create a program that has the user input coordinates and a name to create points. The program must find the points closest to each other and print out their ...
1
vote
4
answers
1k
views
How to remove first character from const char* in C language code
Can anyone please help me? I need to remove the first character from a const char * in C.
For example, const char * contents contains a 'x' character as the first character in the array. I need to ...
-1
votes
2
answers
82
views
Same output when printing out a tree in C
struct Node{
char *key;
struct Node *sx, *dx;
};
typedef struct Node Node;
int main(void){
Node *root = NULL;
char *str = malloc(sizeof(char)*5);
if(scanf("%s", str) == 1) root ...
0
votes
1
answer
116
views
I am trying to create a C program where it will keep asking the user for a string of text and then print it to a file until the user types "end"
I am fairly new at programming and I want to experiment with file pointers. I did my best into trying to find ways to have the user infinitely enter strings and the program will keep inputting it into ...
0
votes
2
answers
65
views
C program to remove all spaces from a given string prints some extra text despite exiting loop
I have written a program to remove all spaces from a given string, and have used a loop to iterate over the string to move over the spaces and add the text in a new string. The code does this but also ...
0
votes
2
answers
37
views
Initialise array of character pointers inside a function to be used in main
How can I initialise array of character pointers inside a function. It should be noted that length comes dynamically from other calculations inside the function. I cannot find length inside main(). ...
-1
votes
3
answers
160
views
Eject excess space from string in C
I need to write a function which will eject excess space from string in C.
Example:
char s[]=" abcde abcde ";
OUTPUT:
"abcde abcde"
Code:
#include <stdio.h>
#...
1
vote
2
answers
112
views
Swap specific text in string
I need to write a function swapLetters that receives two strings. The function transforms the string received as the first parameter by replacing the first character from the string that is passed as ...