473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Incorrect while condition

Hi to all,

I have founded a problem in my program; it is in this code:

i=0;
charRecv = recv(nSocketDesc, &c, 1, 0);
while (c !='\n')
{
mystring[i++]=c;
charRecv = recv(nSocketDesc, &c, 1, 0);
} // End while (c !='\n')
mystring[i]='\0';

I need that while ends when the client press enter key.
But don't happen therefore.Sure, I mistake the condition in "while".
Please, someone can help me?
Thank You and Best Regards.
Gaetano

Apr 10 '07 #1
4 1742
In article <11**********************@l77g2000hsb.googlegroups .com>,
nick048 <ni*************@moonsoft.itwrote:
>I have founded a problem in my program; it is in this code:
>i=0;
charRecv = recv(nSocketDesc, &c, 1, 0);
while (c !='\n')
{
mystring[i++]=c;
charRecv = recv(nSocketDesc, &c, 1, 0);
} // End while (c !='\n')
mystring[i]='\0';
>I need that while ends when the client press enter key.
But don't happen therefore.Sure, I mistake the condition in "while".
Please, someone can help me?
recv is not part of standard C, so as far as this newsgroup is
concerned, we don't know what it does. You should talk to people
who deal with whichever operating system extension is providing
recv() to your program.

In particular, since we don't know what recv() does, we don't
know that when the user presses the enter key that \n is the
character that is sent. It is plausible that when the
user presses the enter key, that \r is sent instead, or some
multi-character code that represents the enter key.

Glacing at the program, I also see a different possibility: namely,
that there might be input buffering on the side of whatever is
providing data to the recv(), so when the user is pressing
the enter key, the data is not necessarily transmitted to the
far end.

A typical way to debug a problem such as this would be to
print out the value of c after the recv(), in a couple of different
formats, so that you can see what value is getting to you and
with what timing.
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
Apr 10 '07 #2
"nick048" <ni*************@moonsoft.itwrites:
Hi to all,

I have founded a problem in my program; it is in this code:

i=0;
charRecv = recv(nSocketDesc, &c, 1, 0);
while (c !='\n')
{
mystring[i++]=c;
charRecv = recv(nSocketDesc, &c, 1, 0);
} // End while (c !='\n')
mystring[i]='\0';

I need that while ends when the client press enter key.
But don't happen therefore.Sure, I mistake the condition in "while".
You problem has only a very little to do with standard C (the topic of
this group) and a lot to do with how to program using sockets (and how
they interact with your OS).
Please, someone can help me?
You will do better over in comp.unix.programmer or at least a group
dedicated to the OS that is hosting your program.

--
Ben.
Apr 10 '07 #3
On Apr 10, 9:48 am, "nick048" <nicosia.gaet...@moonsoft.itwrote:
Hi to all,

I have founded a problem in my program; it is in this code:

i=0;
charRecv = recv(nSocketDesc, &c, 1, 0);
while (c !='\n')
{
mystring[i++]=c;
charRecv = recv(nSocketDesc, &c, 1, 0);
} // End while (c !='\n')
mystring[i]='\0';

I need that while ends when the client press enter key.
But don't happen therefore.Sure, I mistake the condition in "while".
Please, someone can help me?
Thank You and Best Regards.
Gaetano

It looks like you are using the recv() as referenced by the MSDN
article: http://msdn2.microsoft.com/en-us/library/ms740121.aspx

They have an example of how it works. charRecv will be 0 or negative
when there is nothing else to read. You could use that to end the
loop. Look at the examples in the article.

Apr 10 '07 #4
"nick048" <ni*************@moonsoft.itwrote:
# Hi to all,
#
# I have founded a problem in my program; it is in this code:
#
# i=0;
# charRecv = recv(nSocketDesc, &c, 1, 0);
# while (c !='\n')
# {

You can add something like
fprintf(stderr,"charRecv=%d c=%02X %c\n",charRecv,c,c);
and know exactly what c is being set to and why the loop isn't
ending the way you expect. You can guess what is happening
or find out for sure.

# mystring[i++]=c;
# charRecv = recv(nSocketDesc, &c, 1, 0);
# } // End while (c !='\n')
# mystring[i]='\0';
#
# I need that while ends when the client press enter key.
# But don't happen therefore.Sure, I mistake the condition in "while".
# Please, someone can help me?
# Thank You and Best Regards.
# Gaetano
#
#
#

--
SM Ryan http://www.rawbw.com/~wyrmwif/
I ASSURE YOU WE'RE OPEN!
Apr 10 '07 #5

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

Similar topics

3
by: teddysnips | last post by:
In the script below is the DDL to create some tables and a UDF. What I'm interested in is the UDF at the end. Specifically, these few lines: --CLOSE OTRate --DEALLOCATE OTRate ELSE --...
0
by: samuel | last post by:
Hi I wrote a macro in MS Access 2000. This is a .adp link on SQL server tables. I have 2 forms: script_selection & Form3 Form3 include 2 important fields: CD & line I want to write a...
43
by: Dave Vandervies | last post by:
Seen in a chunk of code I was looking at recently (not mine!): -------- char* imgfilename; sprintf((char*)imgfilename, "mask%d.dib", params.profile); ReadImage((char*)imgfilename); --------...
11
by: thborges | last post by:
I tried create this function with DB2 Express and received the error message: -104 Thiago.FUNCTION1: 9: SQL0104N An inexpected token "TABLE SESSION.TESTE(C1 INTEGER) ON CO" was found...
4
by: joh12005 | last post by:
Hello, i posted for suggestions a little idea even if it still needs further thoughts but as i'm sure you could help :) if would like to implement some kind of Condition class which i coud...
49
by: nroberts | last post by:
In the faq for this group: Q: What's the correct declaration of main()? A: There are two valid declarations: int main(void) int main(int argc, char **argv) although they can be written...
16
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of...
1
by: TonyJ | last post by:
Hello! If I have a control in the form that is accessed by a different thread then the one that was used when the control was created I get "Cross-thread operation not valid: Control 'digital'...
0
by: RN1 | last post by:
I have a DataGrid with an EditCommandColumn. In the EditCommand sub of the DataGrid, there is an If condition. This If condition is True for some rows in the DataGrid whereas it is False for the...
0
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,...
0
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$) { } ...
0
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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...
0
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...
0
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...

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.