-
-
while(ch!=' ')
-
{
-
frgt[fr]=ch;
- ch=getc(in);
-
fr++;
-
}
-
fr=0;
-
if(frgt=="DB"|| frgt=="db") //making entry in symbol type field of symbol table.
-
{
-
strcpy(syb_type,"Byte");
-
loc_cntr=loc_cntr+1; //Incrementing location counter values according to the data types encountered.
-
syb_add[sba]=loc_cntr;
-
sba++;
-
syb_add[sba]=' ';
-
sba++;
-
}
-
else if(frgt=="DW" || frgt=="dw")
-
{
-
strcpy(syb_type,"Word");
-
loc_cntr=loc_cntr+2;
-
syb_add[sba]=loc_cntr;
-
sba++;
-
syb_add[sba]=' ';
-
sba++;
-
}
-
else if(frgt=="DD" || frgt=="dd")
-
{
-
strcpy(syb_type,"Double Word");
-
loc_cntr=loc_cntr+4;
-
syb_add[sba]=loc_cntr;
-
sba++;
-
syb_add[sba]=' ';
-
sba++;
-
}
-
while(ch!='\n')
-
ch=getc(in);
-
ch=getc(in);
-
while debugging this program frgt; which is acharachter array has the value "DB" ;but it doen't go in if loop having condition if(frgt=="DB" || frgt=="db").
What can be the reason?
4 1250
You can't compare strings with the == operator. If you want to check a character you can use the == operator, but if you want to check for a string use the strcmp() function.
Let's assume that you initialized fr (to zero) and ch (to getc()) before entering the while-loop. Let's assume that frgt is declared as a char array.
Studlyami is right, you need to call a function to compare two strings. However, you do not yet have a string in the frgt array. You need to write the null character to the end of the character stream within the array to make it a string.
By the way, what protects you from writing past the end of the frgt array? To make your code safe you need to exit the loop just before the array fills up (remember, you need to reserve room for the null character).
Don't confuse the null character with the null pointer. They are two completely different things that happen to have similar names.
@donbock
I checked the value of array, while i was debugging and found that at the end of the array there was a null charachter in the array it was \x0..
so i could have equated the array ending with null charachter with string, array ending with null charachter becomes a string , right?
It is better practice to explicitly write the values you need into the array rather than to trust that the right value will somehow happen to be there on its own.
It is true that the C Standard requires static variables without any explicit initializer to be set to all zeroes before your program begins to execute. However, I suggest that relying on that behavior creates a situation where it is hard for a reviewer or maintainer to understand how the program works. This objection is removed if you carefully and fully document this assumption in a comment.
Even with a good comment, this assumption breaks down if your program loops around to use the variable a second time.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Federico G. Babelis |
last post by:
Hi All:
I have this line of code, but the syntax check in VB.NET 2003 and also in
VB.NET 2005 Beta 2 shows as unknown:
Dim local4 As Byte
Fixed(local4 = AddressOf dest(offset))
...
|
by: justanotherguy63 |
last post by:
Hi,
I am designing an application where to preserve the hierachy and for
code substitability, I need to pass an array of derived class object in
place of an array of base class object. Since I...
|
by: ritchie |
last post by:
Hi,
I am writing to ask if anyone can see why my array is not being sorted
correctly?
It's an array of 4 elements(ints 1,2,3,4) but after calling the
selection sort
it comes back sorted as...
|
by: Gerald |
last post by:
I have a problem with an array of pointers.
In a program I'm writing, I have to read a file, containing thousands
of short lines. The content of another file will be compared against
each line...
|
by: arkobose |
last post by:
my earlier post titled:
"How to input strings of any lengths into arrays of type: char
*array ?"
seems to have created a confusion. therefore i paraphrase my problem
below.
consider the...
|
by: Alexei A. Frounze |
last post by:
Hi all,
I have a question regarding the gcc behavior (gcc version 3.3.4).
On the following test program it emits a warning:
#include <stdio.h>
int aInt2 = {0,1,2,4,9,16};
int aInt3 =...
|
by: intrepid_dw |
last post by:
Hello, all.
I've created a C# dll that contains, among other things, two functions
dealing with byte arrays. The first is a function that returns a byte
array, and the other is intended to...
|
by: Leszek |
last post by:
Hi.
Is it possible in javascript to operate on an array without knowing how mamy
elements it has?
What i want to do is sending an array to a script, and this script should
add all values from...
|
by: sandy |
last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory',
within my class Directory (Can you already smell disaster?)
Each Directory can have subdirectories so I thought to put these...
|
by: assgar |
last post by:
Hi
Seasons Greetings
Its back, I am being haunted.
I thought I had resolved this problem but I am intermittently
the receving the warnings below.
This code consist of a 1) HTML form, 2)...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |