Raised This Month: $51 Target: $400
 12% 

[help] getting 1º char in text


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sn4k3
Senior Member
Join Date: Nov 2005
Old 04-28-2007 , 17:22   [help] getting 1º char in text
Reply With Quote #1

how can i get 1º char in const char *text

like:

const char *text = #firstchar;
or
const char *text = (firstchar;
or
const char *text = $firstchar;

how can i get 1º letter/char (#) ?
sn4k3 is offline
Send a message via MSN to sn4k3
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 04-29-2007 , 06:24   Re: [help] getting 1º char in text
Reply With Quote #2

Do you mean 1st char?
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 04-29-2007 , 06:41   Re: [help] getting 1º char in text
Reply With Quote #3

Use text[0] .
__________________
hello, i am pm
PM is offline
sn4k3
Senior Member
Join Date: Nov 2005
Old 04-29-2007 , 09:02   Re: [help] getting 1º char in text
Reply With Quote #4

i want get 1º letter/simbol in the const char *

like:

const char *text = #test

red thing = 1º letter

now can i get this?
sn4k3 is offline
Send a message via MSN to sn4k3
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 04-29-2007 , 11:56   Re: [help] getting 1º char in text
Reply With Quote #5

1º is all I see, explain yourself man.
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
mooman2
Member
Join Date: Apr 2007
Old 04-29-2007 , 12:42   Re: [help] getting 1º char in text
Reply With Quote #6

Quote:
Originally Posted by PM View Post
Use text[0] .
mooman2 is offline
sn4k3
Senior Member
Join Date: Nov 2005
Old 04-29-2007 , 13:51   Re: [help] getting 1º char in text
Reply With Quote #7

my english is bad but i will try:

how can i get the first letter in a word


like get the #

const char *text = #text

this is for concommand

i want detect what is first letter in the string
sn4k3 is offline
Send a message via MSN to sn4k3
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 04-29-2007 , 14:55   Re: [help] getting 1º char in text
Reply With Quote #8

then
Code:
char *sText = "Hey";
char *sFirstLetter = ( Q_strlen(sText) != 0 ? sText[0] : "" );
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
sn4k3
Senior Member
Join Date: Nov 2005
Old 04-30-2007 , 15:48   Re: [help] getting 1º char in text
Reply With Quote #9

Quote:
Originally Posted by c0ldfyr3 View Post
then
Code:
char *sText = "Hey";
char *sFirstLetter = ( Q_strlen(sText) != 0 ? sText[0] : "" );
very thanks
sn4k3 is offline
Send a message via MSN to sn4k3
showdax
Senior Member
Join Date: Dec 2004
Old 04-30-2007 , 16:02   Re: [help] getting 1º char in text
Reply With Quote #10

Quote:
Originally Posted by c0ldfyr3 View Post
then
Code:
char *sText = "Hey";
char *sFirstLetter = ( Q_strlen(sText) != 0 ? sText[0] : "" );
1. Why are you using Valve's strlen instead of the usual one?
2. Why would you need to check the string's length with strlen in the first place?
3. Why are you returning a value of char to a variable of char* in one branch, but char* in the other? That makes no sense, and I'm not sure if the compiler would implicitly take reference to it, or implicitly cast it. You'd get the exact same value of sText for the former, and for the latter you'd get a garbage pointer.
4. What is wrong with text[0]? It's just going to yield '\0' on zero-length strings.

And if you were wondering, "1º" corresponds to "primo" in Italian--just like "1st" and "first" in English.

Also, let's just try that code:
Code:
brodie:~$ cat test.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    char* s = "Hey";
    char* f = (strlen(s) != 0 ? s[0] : "");

    printf("s: %p\n", s);
    printf("f: %p\n", f);

    return EXIT_SUCCESS;
}
brodie:~$ gcc -Wall -Wextra test.c
test.c: In function 'main':
test.c:8: warning: pointer/integer type mismatch in conditional expression
brodie:~$ ./a.out
s: 0x2df0
f: 0x48
That doesn't look too pretty, now does it?

Last edited by showdax; 04-30-2007 at 16:08.
showdax is offline
Send a message via MSN to showdax
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:18.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode