Questions tagged [strchr]

A C library function which searches for the first occurrence of a character in a string.

strchr is a C library function found in the header string.h. The declaration for it is

char *strchr(const char *str, int c)

This function searches for the first occurrence of the character c (an unsigned char) in the string pointed to by the argument str. It returns a pointer to the first occurrence of the character c in the string str, or NULL if the character is not found.

99 questions
0
votes
3 answers

How can I make my strchr function take both 'const char' and 'char' arrays as first parameter?

I am expecting my function to work just the same as the function "strchr" I am using from the cstring / string.h library. I understand that I cannot cast a " const char* " variable / array to " char* ". Yet, how is the predefined "strchr" function…
M.Ionut
  • 187
  • 1
  • 3
  • 15
0
votes
4 answers

Trying to copy the remainder of a string after a character

I am trying to copy the remainder of a user inputted string. It is always input in the following: airport, 00:00, 00:00. The numbers are flight times and layover times. In my code I've gotten it to spit out the airport, but trying to use strchr to…
RocktheFries
  • 221
  • 2
  • 10
0
votes
3 answers

Searching for substrings using 'srtchr()'

Using the function strchr is it possible to search for a substring in a string instead of a character? Example: Instead of this : int r=strchr("Hello World",'W'); Can this be used : int r=strchr("Hello World","World");
Nnn
  • 191
  • 3
  • 9
0
votes
2 answers

trying to extract complex numbers from strings

I am attempting to extract two columns of numbers from a text file. first column is the real part of the number and the second in the imaginary part. I managed to extract the list of numbers from the file as strings but I don't know how to separate…
0
votes
3 answers

searching for a character throughout 4 strings in c using strchr

I'm having some trouble figuring out why when I run the program it won't let me scan the character I want to search for. It just jumps straight to the last printf statement. int main() { char s1[100], s2[100], s3[100], s4[100]; char character char…
0
votes
3 answers

First index of a non-Whitespace character in astring in C

How do I get the index of the first non-whitespace character in a string. For example for the string " #$%abcd" I would expect getting the index 3 for #.
David King
  • 23
  • 1
  • 2
0
votes
1 answer

C parsing a comma-separated-values with line breaks

I have a CSV data file that have the following data: H1,H2,H3 a,"b c d",e When I open through Excel as CSV file, it is able to show the sheet with column headings as H1, H2, H3 and column values as: a for H1, multi line value as b c d for H2 and…
Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69
0
votes
1 answer

Segmentation fault with g_object_set / strchr

This line get me a segmentation fault : g_object_set(G_OBJECT(data.udpsrc), "port", 5000, "caps", caps, NULL); where data.udpsrc = gst_element_factory_make("udpsrc", "source"); caps = gst_caps_new_empty_simple("application/x-rtp"); Here's the…
kecalace
  • 117
  • 1
  • 16
0
votes
4 answers

Why is my output a null?

#include #include #include #include int main(){ char str [1000] = ""; char ch = 'M'; char *findM; printf("Enter a line of text\n"); scanf("%s", str); findM =…
user7058771
0
votes
2 answers

Iterating string with strchr in C

If I have a string like char str [] = "hello;people;how;are;you" and use strchr(str,";") how can I take the N-th token of the string?
pole gar
  • 53
  • 9
0
votes
2 answers

Using strchr to overload >>

I'm trying to overload the >> operator to read a single (created with enum Symbol {e,a,b,c,d};) Symbol: istream & operator >> (istream & is, Symbol & sym) { Symbol Arr[]={e,a,b,c,d}; char ch; is>>ch; if (strchr("eabcd",ch)) …
0
votes
1 answer

Why does this C code crash?

Can someone explain to me why this code is constantly crashing. Everything seems fine to me. #include #include #include char* find(char *haystack, char needle); int main (){ char haystack[400], needle; …
The Cat
  • 11
  • 1
  • 6
0
votes
1 answer

Trouble with strchr in C

I can't work out why Strchr() is not working in my function. I need to see if the users guess matches any of the letters in a hidden word. It is a Hangman game. int guessLetter(char* word, int* guessedLetters) { char guess[20]; char *s; …
Xarigizel
  • 59
  • 5
0
votes
1 answer

Strchr not working or I need an alternative that checks if any of the characters in a given string are part of another one

So I'm trying to check a string and see if it: has 8 or more chars has at least one uppercase letter has at least one lowercase letter has at least one of the following chars .,?!;:_!@# Here's my code: #include #include using…
AlexxA
  • 21
0
votes
1 answer

Having trouble parsing "file server commands" in C

The commands will be in the form: command filename bytes\nfile_contents I'm having no trouble separating ADD, filename, and the number of bytes, but I am not sure how I can get the remainder of the server command, namely the file contents. This is…
Jonathan Wrona
  • 423
  • 2
  • 7
  • 19