Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I had a line like "kjhdjhdah@lddhfdj".Can you please give me pseudo code to find @ symbol in the line?
Posted
Comments
Sandeep Mewara 4-Nov-12 8:29am    
It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.

Comment in solution suggests you want it in C++?

C++
std::string s("kjhdjhdah@lddhfdj");
size_t location = s.find("@");
std::cout << location << std::endl;


Outputs "9"
 
Share this answer
 
Comments
Tarun Batra 22-Feb-14 9:08am    
please reply in this http://www.codeproject.com/Questions/731791/File-ponter-maintaince-error-please-guide
Start here[^] and here[^] and spend some time studying. If you want to find out how to manipulate characters within strings then find the entry for std::string in the library section and check all the available methods; there will probably be one called find()[^]. You should really get familiar with the MSDN documentation, as I have suggested to you in a number of your previous questions.
 
Share this answer
 
Comments
Tarun Batra 22-Feb-14 9:08am    
please reply this http://www.codeproject.com/Questions/731791/File-ponter-maintaince-error-please-guide
Richard MacCutchan 24-Feb-14 3:57am    
What does this mean?
use
C++
char * strchr ( const char *, int ); 

consider the example below.

C++
/* strchr example */
#include <stdio.h>
#include <string.h>

int main ()
{
    char str[] = "This is a sample string";
    char * pch;
    printf ( "Looking for the 's'character in \"%s\"...\n", str );
    pch = strchr(str,'s' );
    while ( pch != NULL )
    {
        printf ( "found at %d\n", pch - str + 1 );
        pch = strchr( pch + 1, 's' );
    }
   return 0;
}</string.h></stdio.h>
 
Share this answer
 
Use strchr() function.

C#
char *strchr(
   const char *string,
   int c 
);
);


Returns a pointer to the first occurrence of c in string, or NULL if c is not found.
For Unicode version, wcschr can be used.
 
Share this answer
 
v2
Comments
Tarun Batra 4-Nov-12 7:10am    
Sir i want to read a line from a file then i take it into a string using getline,getline doesnt work with char *
Santhosh G_ 4-Nov-12 7:29am    
Use c_str() function of string.
strchar( strObj.c_str(), '&' );
Quirkafleeg 6-Nov-12 5:06am    
If you're going to use the C++ string, why use a C function?
Santhosh G_ 6-Nov-12 7:37am    
"C" is also tagged in the question. Anyway string::find() also an option to find the character in the string.
Tarun Batra 22-Feb-14 9:08am    
please reply this http://www.codeproject.com/Questions/731791/File-ponter-maintaince-error-please-guide

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900