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

Finding duplicate chars in argv[]

I'm trying to scan through my arguments list, argv[], and determine if there are duplicate chars. I've tried a few things, but nothing seems to work. I'm really new at C so bear with my horrible code: char unavailableLetters[26] = ""; int pos =…
Nelson.b.austin
  • 3,080
  • 6
  • 37
  • 63
0
votes
0 answers

NASM pointer operation

i'm stuck with a NASM code, i'm trying to reproduce the strchr function in NASM and i can't figure out two things : -Why when i try to print the result i got a warning on wrong format with a printf %s even if i'm trying to return a pointer on a…
Hakeem El Bakka-lee
  • 756
  • 1
  • 7
  • 23
0
votes
1 answer

C alternative to PHP's explode function

So, i'm looking for a C function that does the equivalent to PHP's explode function. For those who are not familiar: Explode grabs a string and parses each entry separated by the given char/escape sequence. the best part about this function is its…
zecoxao
  • 3
  • 3
0
votes
1 answer

strchr(), How does this correctly find the index of a char

I'm looking at the example for strchr() on: http://www.cplusplus.com/reference/cstring/strchr/ Why does this correctly find the index? Intuitively it looks like it should be giving a negative index: #include #include int main…
asimes
  • 5,749
  • 5
  • 39
  • 76
0
votes
1 answer

strrchr only displaying items in string after slash

I'm referencing to an array and this is only showing the part of string after the slash. How do I show the characters before it also. #Check for bio if ($biosDisplayed == $y) { $positionTitle = strpos($bios[$i], " /"); …
Woovils
  • 3
  • 1
0
votes
1 answer

Detect vowels in a string

Im trying to write a function that detects vowels and digits in a string. iterating through the string, im trying to do a one-line if statement to check if a character is a vowel. Code as below... void checkString(char *str) { char myVowels[] =…
kype
  • 555
  • 1
  • 6
  • 24
0
votes
1 answer

C : strchr pointer value doesn't change

I'm trying to recursively search for a substring in a string using C program. I wrote the following piece of code. The issue I'm facing is that, the ptr value, though it prints the correct value(using puts in the beginning of while), while usage its…
Gomu
  • 1,004
  • 5
  • 16
  • 36
0
votes
1 answer

First occurrence except escaped chars in C

How can I locate the first unescaped char in a str. In the following code, I get the first char at position 14, but I'm looking the one at position 26. #include #include int main () { char str[] = "FOO + pHWAx \\\"bar…
Kayla
  • 899
  • 2
  • 6
  • 16
-1
votes
2 answers

Having some confusion with pointers

I have the following code that I'm trying to decipher from a former colleague: void getIP(int p){ char tstr[80]; char *pt; strcpy(ipBuf,"NA"); if(p==-1)return; strcpy(tstr, panes[p].stream.c_str()); pt=strchr(tstr,':'); …
Cm1602
  • 91
  • 11
-1
votes
2 answers

How to define "strchr(s,oldch)" in function definition in c program?

I am a beginner to C language. I dont understand the function defintion part. What does "strchr(s,oldch)" do? I am trying to convert it into ctypes program. #include #include #include /* Replace och with nch in s and…
shaila
  • 177
  • 2
  • 10
-1
votes
1 answer

How to check a if a string contains a letter in c?

I have to check if a character(string) contains a scanned letter. char password[15]="STACKOVERFLOW"; char check; printf("Type in a letter to check if it is in the password/n"); scanf("%c", check); Now I want to check if the check is in the password…
-1
votes
2 answers

Why is my strchr not looping? I want it to output the number for however many times it sees '.' or ' !' or '?'

I know strchr only gets the first instance. But why is my loop not working. No matter how many times '.' or ' !' or '?' is used in the text. It keeps outputting 3. //this finds number of sentences int Y = 0; while (ch != '\0'); …
user13703703
-1
votes
1 answer

C strchr causing "Invalid read of size 1" in valgrind

I'm running through a program and although the code is working fine, Valgrind is showing an 'Invalid write of Size 1' and Address 0x1ffefffa00 is on thread 1's stack.This has happened using both strchr and strchrn, another function in the…
-1
votes
1 answer

C++ pointers and string vectors

//Add words from the file to the vector while (inputFile >> word) { listWords.push_back(word); wordCount +=1; //Count the words } for (int i = 0; i < listWords.size(); i++) { char *p; p = strchr(listWords.at(i), 'c'); if ( p !=…
-1
votes
2 answers

Could anyone help me to understand this strchr() C Segmentation fault?

I'm diving into pointers and strings in C and I'm still getting used to some concepts. I tried to implement a version of the strchr() function – the same as in string.h – for study purposes, but something basic is still not right. Here's my…
ulissesBR
  • 93
  • 11