Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C Visual-Studio
I had a line like "kjhdjhdah@lddhfdj".Can you please give me pseudo code to find @ symbol in the line?
Posted 4-Nov-12 0:14am
Comments
Sandeep Mewara at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
Comments
Tarun Batra at 22-Feb-14 9:08am
   
please reply this http://www.codeproject.com/Questions/731791/File-ponter-maintaince-error-please-guide
Richard MacCutchan at 24-Feb-14 3:57am
   
What does this mean?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use strchr() function.
 
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.
  Permalink  
v2
Comments
Tarun Batra at 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_ at 4-Nov-12 7:29am
   
Use c_str() function of string.
strchar( strObj.c_str(), '&' );
Quirkafleeg at 6-Nov-12 5:06am
   
If you're going to use the C++ string, why use a C function?
Santhosh G_ at 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 at 22-Feb-14 9:08am
   
please reply this http://www.codeproject.com/Questions/731791/File-ponter-maintaince-error-please-guide
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

use
char * strchr ( const char *, int ); 
consider the example below.
 
/* 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>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Comment in solution suggests you want it in C++?
 
std::string s("kjhdjhdah@lddhfdj");
size_t location = s.find("@");
std::cout << location << std::endl;
 
Outputs "9"
  Permalink  
Comments
Tarun Batra at 22-Feb-14 9:08am
   
please reply in 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)

  Print Answers RSS
0 OriginalGriff 205
1 Sergey Alexandrovich Kryukov 185
2 jlopez788 144
3 Rob Philpott 100
4 Prakriti Goyal 97
0 OriginalGriff 6,837
1 Sergey Alexandrovich Kryukov 5,559
2 Maciej Los 3,479
3 Peter Leow 3,323
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 6 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100