Questions tagged [string.h]

A header file from the C standard library that defines various functions for interacting with C strings.

In C a string is a null-terminated set of contiguous char values, often referred to via a pointer. The string.h header defines many common methods for interacting with such strings. These methods are guaranteed to be portable as a part of the standard library, but may have other limitations or security concerns.

138 questions
2
votes
4 answers

Why won't certain C string library functions (i.e. strtok) accept a char * that hasn't been allocated with malloc?

Recently I was working on a school project which involved writing an assembler in C, and I encountered a problem with passing a pointer to strtok. I got past the error in my code, but I want to understand why what I was doing didn't work. Below is…
Sam Hazleton
  • 450
  • 1
  • 5
  • 20
1
vote
2 answers

Android NDK Samples Compilation error: string.h: No such file or directory

I'm trying to compile the Android ndk example android-ndk-r6b/samples/hello-jni and i'm not having luck. The compilation error i'm getting is: $:/media/rober/android/android-ndk-r6b/samples/hello-jni$ ndk-build Gdbserver :…
Robert Estivill
  • 11,585
  • 7
  • 36
  • 60
1
vote
0 answers

On MacOS Catalina with latest XCode, __DARWIN_C_LEVEL is too low for String.h... what should I do?

I'm starting a new job. I'm a windows guy that has been working in the Microsoft stack for decades. The new job calls for work to be done on a Mac, and I'll be working in straight C code. It's interesting, and I vaguely remember using it a tiny…
Kevin
  • 53
  • 7
1
vote
3 answers

How to concatenate two charcters in c?

I am new to c . When i try to do char a = 'h'; Char b = 'j'; Strcat(a,b); I get an error because a and b must be two strings . So how can i do this ?
1
vote
2 answers

Can't understand the usage of strchr to get the position of a charcter in a string in C

This code will output the index of a charcter in a string : #include #include int main(void){ char str[100]="birds are dying"; char *p; p = strchr(str,'e'); int i=p-str; printf("%d" , i); return 0; } the…
1
vote
5 answers

C change string between character

Suppose I have a string "hello_from_here". I would like to change the sub-string that is between the '_', for instance "hello_21223_here". I suppose that I should use strtok, but I've not been successful so far. So far I was trying to do: char…
II K
  • 97
  • 1
  • 6
1
vote
2 answers

What is the difference between a 2D string of the type string[10][20] compared to a 2D string of the type *string [10][20] in C?

I am a beginner in C and I use CodeBlocks for Windows. I learnt that a string is a sequence of characters (chars) but I needed a sequence of strings. In a video I saw that if I use a pointer in my string (it was char string[20][10] and now it is…
KazzioBots
  • 37
  • 3
1
vote
1 answer

Function strspn from string.h not working properly

I have a program in C which stores a list of students working with linked lists as college project. typedef struct { int day; int month; int year; } date_t; typedef struct { char name[50]; int dni; char email[30]; float…
Pol Vilarrasa
  • 162
  • 12
1
vote
0 answers

Comparing two strings with strcmp() give EXC_BAD_ACCESS

I have this function to insert a node in a red-black tree. The order key of this red-black tree is the string id_prod value, compared by the function strcmp. When I try to insert a node in this structure Xcode give to me this alert…
1
vote
1 answer

String bug in my_shell program

I'm trying to create a simple shell program which execute the program specified in input. There are two main function: scanner() (use strtok to split the input in token) and execute() (fork the process and execute the program). Unfortunately it…
sworwitz
  • 19
  • 7
1
vote
1 answer

"Free heap block modified after it was freed" when modifying string after malloc

I am currently working on a project that includes some file I/O. Due to it being cross platform I needed to account for different path separators and hence decided to create the following function to simplify the process of joining paths: /** *…
luke
  • 953
  • 6
  • 17
1
vote
2 answers

How to suppress shadow "index" warning?

I maintain a cross-platform C codebase and on a few platforms (Xcode 4, Red Hat derived distros like Fedora and Mageia), I get the following compiler error: warning: declaration of 'index' shadows a global declaration Based on this answer, I…
congusbongus
  • 10,870
  • 5
  • 64
  • 86
1
vote
0 answers

Strings sorting with matrices

I am participating to a tournament and I have a problem with strings sorting. Here I try to explain the situation: "A man discovered a big book written in an unknown language that used the same characters as the English language. The book contained…
Alberto Miola
  • 4,066
  • 8
  • 31
  • 45
1
vote
5 answers

Check if a word is palindrome with string.h

I must do a program that tells me if a string is palindrome or not using the library string.h . I wrote the following code but the output is always "palindrome" #include #include #include int main() { char…
Alberto Miola
  • 4,066
  • 8
  • 31
  • 45
1
vote
3 answers

fgets() getting stuck in infinite loop

If I am using the fgets() function to search for a specific delimiter throughout a text file, how do I make sure the fgets() does not infinitely loop at the EOF? I am concatenating all the lines from delimiter1 through delimiter2 into…
Sean Sen Wang
  • 193
  • 1
  • 1
  • 11
1 2
3
9 10