We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Mustafa Açık • 5 years ago

this expression helped me. Thanks a lot. Greetings from Turkey

Donotalo • 5 years ago

Thank you. I'm please to know that it helped you.

Yushu Jian • 2 years ago

Thank you so much, this is the best tutorial I found about manipulating strings in C. Nice one

Rajendra prasad reddy • 2 years ago

Can some one please help me, How to add array of string arrays in c programming

Abelardo León González • 3 years ago

Hi there,

When I declared & initialized this array:
char palos[NUM_PALOS][MAX_LONG_PALOS] =
{
"oros",
"copas",
"espadas",
"bastos"
};

and prints out the third position palos[2] should print "espadas" but "espadasbastos" is outputted. NUM_PALOS = 4 and MAX_LONG_PALOS = 7.
It happens on Ubunt 20.10 with C99 & CLion as IDE.

What's wrong?

Best regards,

Garimedes • 2 years ago

I assume MAX_LONG_PALOS has to be at least 8 in order to fit the NULL character at the end of "espadas". Otherwise the array will be stored in memory like this:
{ 'o', 'r', 'o', 's', '\0', 'c', 'o', 'p', 'a', 's', '\0', 'e', 's', 'p', 'a', 'd', 'a', 's', 'b', 'a', 's', 't', 'o', 's', '\0' }
and when you request palos[2], the compiler does not know to stop at the end of "espadas", but reads into the next array, resulting in "espadasbastos".

Vaibhav Hake • 3 years ago

i want to get following string from user, how to do that

char arr[NUMBER_OF_STRING][MAX_STRING_SIZE] =
{ "array of c string",
"is fun to use",
"make sure to properly",
"tell the array size"
};

and then want to print the same

Nishikant Hingole • 3 years ago

Hello,
I am searching for the solution to extract pertecular string from the given string

$PMTK011,MTKGPS*08
$PMTK010,001*2E
$PMTK011,MTKGPS*08
$PMTK010,002*2D
$GPRMC,064512.498,V,,,,,0.00,0.00,270121,,,N*4B
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,064512.498,,,,,0,0,,,M,,M,,*49
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,00*79
$GLGSV,1,1,00*65
$GPGLL,,,,,064512.498,V,N*7B
$GPTXT,01,01,02,ANTSTATUS=OPEN*2B

I want to extract

$GPRMC,064512.498,V,,,,,0.00,0.00,270121,,,N*4B


Please help me out

Denis Dos Santos Silva • 2 years ago

sscanf

Aqsa • 3 years ago

I have a file instead of string array and file contain lines i want to split comma separated words and using a loop which can automatically pass to the next line after the 1st line words completed.. kindly help me with this.

Philipe • 3 years ago

how to store result in new variable instead of print?

Peter • 3 years ago

Hi. There is a wrong basic assumption in this article. An array is not necessarily stored sequentially in memory. The first char can be stored in one memory location and the next in an entirely other location in memory, so you cannot simply advance the pointer by one.

upendra chaudhari • 4 years ago

these tutorials are still much better than many other similar websites or youtube channel

Gsb2 • 4 years ago

If I wanted to split a string using with char delim[] = "dr", is there any way that I can find out which character did was using to delimit every time it does that. For example, if the string is 40d50r30d.., is there any way that I could know that the 40 was delimited by the char d and the 50 was delimited by char r and likewise

Sunil Sheth • 4 years ago

Good tutorial with proper example
Thanks

hopefor • 4 years ago

I m signed up for ask this,why i must use define ? When i create an integer variable and put into char arr[x][y] as x and y integers i get an error.I wonder why this cause to an error?And thanks for post by the way

Donotalo • 4 years ago

In C you can't declare arrays as char arr[x][y] where x and y are variables. The compiler must know the size of the array at compile time. So you must declare the size as constant.

hopefor • 4 years ago

hmm, thanks for the info

shivam panchbhai • 4 years ago

suppose there are two strings and i need to find if the 1st character of the 1st string is present in the 2nd string then how to write code for this?

PaulEmmons • 3 years ago

It sounds as though strchr() would do that.

Srinivasan1 • 5 years ago

how to split Audi@9.8 as car nmae and its mielage and store it seperately

Donotalo • 5 years ago

You need to use strtok with '@' character, then use strcpy to copy the tokenized string to another string.

srini • 5 years ago

how to split Audi@10.8 as car name and mielage and store seperately

Donotalo • 5 years ago

Please check my previous answer.

Anonymous • 5 years ago

hello thank you this help. here I am able to split token,
But can you help how can i store each part of token in different variable?

Vikas Gupta • 4 years ago

use string array

Anonymous • 1 year ago

hi iam trying for user id and password in command line interface
FORMAT: adduser <username> <password> <confirm password="">
how can i store and compare these parameters using strtok ?