All Questions
72 questions
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 ...
1
vote
1
answer
43
views
Extra characters appearing when pthread_create is called with a struct as an argument to the thread
I observed that when I pass a struct as an argument to the thread, the string member of the struct is few characters longer inside the thread.
So basically, in main, s-dev is 12 characters long. And ...
-1
votes
3
answers
980
views
Understanding parameters of strlen in C
I am a bit confused on why my code is not iterating a string in C programming.
Essentially.
I have this function here
int atoi(const char *s[]){
printf(" The length is %d",strlen(s));
...
-4
votes
1
answer
404
views
.length(), strlen(n), and sizeof(n) does not work with string and cstring [closed]
I'm trying to write code that outputs the length of a string.
int main(){
string s1, s2;
scanf("%s %s", &s1, &s2); //Doesn't work.
cin >> s1, s2; //Works, I inputed ...
0
votes
3
answers
184
views
Trying to output the length of a string using strlen() through a pointer
I am trying to output the length of a string using strlen(). But I want to do it through a pointer.
Here's what I tried:
`
#include <stdio.h>
#include <string.h>
int main()
{
char a[]=...
0
votes
1
answer
80
views
Why is strlen conting the null character here? [duplicate]
Normaly strlen does not count the null terminator at the end of the string. But the below code prints the string count with the null terminator. Can anyone explain me why?
int main(){
char name[...
0
votes
1
answer
242
views
How to get string length in function
How can I get the length of the buffer in the function using pointers?
#include <stdio.h>
#include <stdlib.h>
void fun(char *(buffer))
{
printf(strlen(buffer));
}
int main()
{
...
1
vote
2
answers
2k
views
Recursion to find length of a string in C
I am trying to find the length of a string by recursion using the following code:
#include <stdio.h>
int string_length(char *s, int x);
int main(void)
{
int length = 0, x;
char string[] ...
1
vote
1
answer
275
views
Unexpected Printed Exclamation Mark - cs50 Substitution
Completing cs50's Substitution project. The program is supposed to use a key inputed in the command-line to 'encode' a message (string). My program works fine but for some strange reason it prints an ...
-2
votes
2
answers
131
views
cannot append string in C (program stops)
I'm trying to append a string, but whenever it gets to the strcat() function the program exits without printing the string.
I've been running this code from within Visual Studio as well as from its ...
0
votes
2
answers
59
views
I don't know why length is +1 than real in textfile
The following code check the longest word in a string.
char *fp2 = strtok(str, " .");
if (fp2 == NULL) {
if(strlen(str) >= length) {
length = strlen(str);
}
} else if (...
-1
votes
1
answer
148
views
Write a program that reads a short string and a longer string and checks if the longer string starts with the letters of the short string. Use strncmp
I need help getting this code to work. Could someone tell me how to properly use strncmp and how to get this to work?
Example: Enter first string: john
Enter second string: johnson
johnson does ...
1
vote
1
answer
986
views
Include spaces when counting the length of a string
Im trying to create a simple program that reads strings entered by the user and displays the longest and shortest string. The program works fine for single words such as 'dog' or 'cat' but if I was to ...
1
vote
7
answers
408
views
Strlen, Malloc and address arithmetic
Need some help breaking down this C function. I'm stuck on the malloc line. I do not understand what the "+8" is doing and/or why it is even there. My research revealed it has something to ...
1
vote
3
answers
832
views
Function to concatenate two strings in C using strlen but without using strcat
I need to concatenate the strings "abc" and "def" using strlen but without using strcat. Can someone show me what is wrong with my main() function?
#include <stdio.h>
#...