Solved

Arrays last character will be "/" ?

Posted on 2006-07-16
3
251 Views
Last Modified: 2010-04-15
Usually in a char[] array in C, the last character will be "/" ?

char  sz[7];
sscanf(line, "level %s",  &sz[]);
for (int i = 0; sz[i] == "/"; i++)
{
if (sz[i] == ":")
continue;
.....
.....
}

sz[] will be getting value in the format 120:0
So can I use the above to trace through sz[] array from beginning till the end?
If its wrong please guide me the correct way.
Thanks.
0
Comment
Question by:gopikrish
3 Comments
 
LVL 16

Accepted Solution

by:
PaulCaswell earned 25 total points
ID: 17118103
Hi gopikrish,

The normal way to walk a string looks something like:

for ( i = 0; s[i] != '\0'; i++ )

Although some shorten it to:

for ( i = 0; s[i]; i++ )

which I personally dont like but is acceptable.

Why do you thing that there is a "\" at te end of a string?

Paul
0
 
LVL 8

Assisted Solution

by:manish_regmi
manish_regmi earned 25 total points
ID: 17119170
>> Usually in a char[] array in C, the last character will be "/" ?

No, Usually in a char[] array in C, the last character will be '\0' (null character) not "/"

characters are enclosed in '' not in "".

i dont know what you are trying to achieve but it should be

char  sz[7];
sscanf(line, "level %s",  &sz[]);
for (int i = 0; sz[i] != '\0'; i++)
{
if (sz[i] == ':')
continue;
.....
.....
}

regards
Manish Regmi
0
 
LVL 7

Expert Comment

by:nafis_devlpr
ID: 17128766
the last character of a C-array according to C99 standards should be '\0', there is no way it could be '/'

so what you have to do is this

char  sz[7];
sscanf(line, "level %s",  &sz[]);
for (int i = 0; sz[i] != '\0'; i++) // or for (int i = 0; sz[i]; i++)
{
if (sz[i] == ":")
continue;
.....
.....
}
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now