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
-1
votes
2 answers

strchr not working in C

So right now I'm trying to code a program in C that takes a string and checks for proper punctuation (e.g. ends with '.', '?', or '!'). I am trying to use the strchr function to test and see if the last character in the string is one of the…
JMWBZ
  • 13
  • 1
  • 4
-1
votes
1 answer

Why this program doesn't give right result when used with large strings?

This program takes an input of number of strings followed by the actual strings. The output should be the number of common characters to all strings. The constraints are: No of strings <= 100 Length of string <= 100 For…
SomeDevloperName
  • 622
  • 1
  • 6
  • 10
-2
votes
1 answer

Get part of string(chars) before / in C

I want to get part of a string from a user's input if "/" is provided in the input. I used the strchr() function to check for "/". My actual problem is to be able to get the first string before / like dir/filename.txt, I want to get dir from the…
Abdellah
  • 17
  • 4
-2
votes
1 answer

C - using strchr inside memcpy

I am trying to make a simple code sample, in which I can have a sub-string, into a new string. My code is below: char titulo[20]; char line[] = "PRINCIPAL,1.Liga,2.Clubes,3.Jogadores,4.Relatorios,5.Sair;"; char *pos =…
Rafael Botas
  • 125
  • 1
  • 1
  • 9
-2
votes
1 answer

strpos() show n character before and after specified word

I wrote a simple search engine and want to show some text in result, actually I want to show 200 character before SEARCH QUERY and 200 character after SEARCH QUERY. Example: SEARCH QUERY: TEST RESULT: BLAH BLAH BLAH BLAH BLAH BLAHBLAH BLAH…
Pedram
  • 15,766
  • 10
  • 44
  • 73
-2
votes
1 answer

use of strchr() giving error

I am trying to find the occurrence of characters of one string(s1) in other string(s2). This is part of my code. for(;i0) count++; } But on compiling I get an error pointing to strchr() and…
nomorequestions
  • 589
  • 2
  • 6
  • 20
-3
votes
4 answers

What is wrong with my version of strchr?

My assignment is to write my own version of strchr, yet it doesn't seem to work. Any advice would be much appreciated. Here it is: char *strchr (const char *s, int c) //we are looking for c on the string s { int dog; //This is the index on the…
-4
votes
2 answers

Why did I get error by using strchr() in C++?

#include #include #include using namespace std; int main(){ string a="asdasd"; if(!strchr(a,'a')) cout<<"yes"; return 0; } I just began to learn C++ programming and I don't know why I got error in this…
user299560
  • 15
  • 5
-5
votes
2 answers

why *s and *s++ have the same value in the following situation?

char *s; char buf [] = "This is a test"; s = strchr (buf, 't'); if (s != NULL) printf ("found a 't' at %s\n", s); printf("%c\n",*s); printf("%c\n",*s++); printf("%c\n",*s++); printf("%c\n",*s++); printf("%c\n",*s++); This code outputs: found…
Liyuan Liu
  • 105
  • 1
  • 1
  • 6
1 2 3 4 5 6
7