?
Solved

Arrays last character will be "/" ?

Posted on 2006-07-16
3
Medium Priority
?
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Accepted Solution

by:
PaulCaswell earned 100 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 100 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

777 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