473,487 Members | 2,622 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Not executing the body of a if statement

suzee_q00
16 New Member
I think the program recognized that it has found a match because it no longer gives me the Undefined Command message but it will not execute the body of the if statement.

Here's my handy dandy code. Please let me know if anything is unclear from this snippet. I am never sure how much of the code I need to provide.
Expand|Select|Wrap|Line Numbers
  1. // Loop until there are no more commands in input file
  2.    while ( fgets ( cmdStr, BUFLEN, fin ) != NULL )
  3.    {
  4.       printf(cmdStr);
  5.       rmNl(cmdStr);
  6.       if ( lineWithBlanks ( cmdStr ) )
  7.          continue;
  8.       else
  9.       {
  10.          if (strEQ (cmdStr, "ADD"))
  11.          {
  12.             /*   read the next 6 lines into the phone structure   */
  13.             fgets(cmdStr, BUFLEN, fin);
  14.             while (!lineWithBlanks)
  15.             {
  16.                scanf(cmdStr, "%s %s", phoneRec.fName, phoneRec.lName);
  17.                fgets(cmdStr, BUFLEN, fin);
  18.                scanf(cmdStr, "%s", phoneRec.address);
  19.                fgets(cmdStr, BUFLEN, fin);
  20.                scanf(cmdStr, "%s", phoneRec.city);
  21.                fgets(cmdStr, BUFLEN, fin);
  22.                scanf(cmdStr, "%s", phoneRec.state);
  23.                fgets(cmdStr, BUFLEN, fin);
  24.                scanf(cmdStr, "%d", &phoneRec.zip);
  25.                fgets(cmdStr, BUFLEN, fin);
  26.                scanf(cmdStr, "%s", phoneRec.key);
  27.             }
  28.                insertNode (&head, phoneRec);       /*  create node   */
  29.          }
  30.          else if ( strEQ (cmdStr, "PBLN"))   /*   print by last name   */
  31.             ;
  32.          else if ( strEQ (cmdStr, "DBPN"))   /*   delete by phone number   */
  33.             ;
  34.          else if ( strEQ (cmdStr, "DBLN"))   /*   delete by last name   */
  35.             ;
  36.          else if ( strEQ (cmdStr, "PDIR"))   /*   print directory   */
  37.             printList (&head);
  38.          else
  39.             printf ("Undefined Command\n");
  40.        }
  41.      }
  42.  
  43.  
Here is the output I am getting:
ADD
1111
Undefined Command
22 33 44 55 66
Undefined Command
99 88 77
Undefined Command
After it recognizes "ADD" it should store 1111 ... in the structure instead of going back and treating them as command

Any help would be greatly appreciated :)
Suze
Mar 28 '06 #1
1 1394
suzee_q00
16 New Member
I figured out the previous problem and created a new one for myself. Ain't that always the way. The problem with the other code was line 14 I didn't pass a value to linewithblanks so the not would never be true and it hops out of the loop and continues on it's merry little way.

Why waste a good thread . . . Now for the new problem. I seem to have created an infinite loop for myself. I only removed the if linew/... and it accompanying brackets I am don't see where the loop comes in.

Here's the latest code
Expand|Select|Wrap|Line Numbers
  1. // Loop until there are no more commands in input file
  2.    while ( fgets ( cmdStr, BUFLEN, fin ) != NULL )
  3.    {
  4.       printf(cmdStr);
  5.       rmNl(cmdStr);
  6.       if ( lineWithBlanks ( cmdStr ) )
  7.          continue;
  8.       else
  9.       {
  10.          if (strEQ (cmdStr, "ADD"))
  11.          {
  12.             /*   read the next 6 lines into the phone structure   */
  13.             fgets(cmdStr, BUFLEN, fin);
  14.             scanf(cmdStr, "%s %s", phoneRec.fName, phoneRec.lName);
  15.  
. . .
Mar 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
6148
by: Glenn Davy | last post by:
Hidely hodley everyone I'd like to run a series of of sql ddl statements against an msde2000 server. Normally I just deploy cmd file that impliments as osql statement, but I'd like to store the...
10
3374
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
1
25611
by: csj | last post by:
I'm having a problem with my PHP script. When the user arrives on my page there is an item for sale for them to buy. The user already has 200 points stored in their database row. I want it work...
8
3097
by: lovecreatesbea... | last post by:
K&R 2, sec 2.4 says: If the variable in question is not automatic, the initialization is done once only, conceptually before the program starts executing, ... . "Non-automatic variables are...
2
5200
by: Divakar | last post by:
Hi, How can we find which SQL statement is executing when "list application show detail" shows "UOW Executing" against an application. This topic was touched upon earlier by one of the member....
4
7649
by: Mahesh S | last post by:
Hi I want to write a user defined function which does the following. 1. Take a string value as input parameter 2. Should execute a sql statement: select col1, col2, col3, col4 from table_name...
5
2456
by: reycri | last post by:
Hi, I need to be able to do this: var func = new Function("var me = <selfRef>; alert(me.params);"); func.params = "This is a test parameter"; window.setTimeout(func, 500); Basically, I...
3
4778
by: lbarrack | last post by:
I am writing a timepunch addition to an existing timecard web app using ASP and Internet Explorer tied to a SQL 7 backend. I have isolated enough of the problem down to what I think is trying to...
2
2629
by: krishna.000.k | last post by:
file1.py ---------- a = 20 from abc import * print "Should this be printed when 'a' is alone imported from this module" file2.py ---------- from file1 import a
0
7106
marktang
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,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7181
jinu1996
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...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4874
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.