Help with string 
Author Message
 Help with string

Hello!

I would like to extract letters from files. I am using:

      sscanf (line, "%4c", atoms[total_lines].name);

      atoms[total_lines].element[0] = atoms[total_lines].name[0];
      if (isalpha(atoms[total_lines].name[1])) {

        atoms[total_lines].element[1] = atoms[total_lines].name[1];
        atoms[total_lines].element[2] = '\0';

      } else {

        atoms[total_lines].element[1] = '\0';

      }

Now I have a problem. Second leter can be capital or small. CA or Ni. I
must read only those with small second letter.

Help please

CCCao
--
miha



Sun, 27 Jun 2004 21:50:05 GMT  
 Help with string


Quote:
> Hello!

> I would like to extract letters from files. I am using:

>       sscanf (line, "%4c", atoms[total_lines].name);

>       atoms[total_lines].element[0] = atoms[total_lines].name[0];
>       if (isalpha(atoms[total_lines].name[1])) {

> atoms[total_lines].element[1] = atoms[total_lines].name[1];
> atoms[total_lines].element[2] = '\0';

>       } else {

> atoms[total_lines].element[1] = '\0';

>       }

> Now I have a problem. Second leter can be capital or small. CA or Ni. I
> must read only those with small second letter.

> Help please

> CCCao
> --
> miha

Hint:  There are two functions to test the case of a letter in C: isupper()
and islower(), both in <ctype.h>.  Both of them are locale-dependent,
though, and I don't know where you're posting from. But they are guaranteed
to work on the letters of the English alphabet at the very least in the C
locale.

Gregory Pietsch



Sun, 27 Jun 2004 23:11:18 GMT  
 Help with string


Quote:
> Hello!

> I would like to extract letters from files. I am using:

>       sscanf (line, "%4c", atoms[total_lines].name);

>       atoms[total_lines].element[0] = atoms[total_lines].name[0];
>       if (isalpha(atoms[total_lines].name[1])) {

> atoms[total_lines].element[1] = atoms[total_lines].name[1];
> atoms[total_lines].element[2] = '\0';

>       } else {

> atoms[total_lines].element[1] = '\0';

>       }

> Now I have a problem. Second leter can be capital or small. CA or Ni. I
> must read only those with small second letter.

#include <ctype.h>

/* etc */

if(islower(some_char))
   do_stuff();

/* etc */

-Mike



Mon, 28 Jun 2004 03:09:34 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. newbie needs help to strings, strings, strings

2. Help about string & sub-string

3. Help: Convert string to decimal (or double)

4. S-Language,help with strings,char arrays?

5. Help with Strings

6. need urgent help for string processing

7. Help with strings and parsing

8. Beginner help with strings

9. Beginner needs help with strings, pointers, arrays

10. Help - reverse string

11. Need help with String Array

12. please help newbie string replacement in big file

 

 
Powered by phpBB® Forum Software