Programming - C/C++


From: JnZ jouweihu@comp.nus.edu.sg
Skaven <sohsengh@comp.nus.edu.sg> wrote:
->May I know if there's any editors in unix that can read and display C/C++
->files with colours that mark reserved words a la VC++ ?

Yes. gvim/vim with syntax highlighting turned on.

From: "Metropolitan" <chonghsi@iscs.nus.edu.sg>
Subject: C - division to get decimal
Date: Thu, 14 Jan 1999 14:18:06 +0800

how do we do a division to get a real number in C?
not qoutient or remainder but the real number .... thanks
From: JnZ <jouweihu@comp.nus.edu.sg>
Subject: Re: C - division to get decimal

Typecast to float or double.

From: BLUE NOSE <lanbin@iscs.nus.edu.sg>
Subject: [vc++]error C2059
Date: 18 Jan 1999 10:58:28 GMT

error c2059:syntax error :'end of file'

Any 1 can some tips? I delete the last line
several times but cant solve.

TIA!
From: JnZ <jouweihu@comp.nus.edu.sg>
Subject: Re: [vc++]error C2059
Date: 19 Jan 1999 03:02:48 GMT

Maybe you have an unclosed } or " somewhere.
From: BLUE NOSE <lanbin@iscs.nus.edu.sg>
Subject: Re: [vc++]error C2059
Date: 19 Jan 1999 05:30:06 GMT

I dont think so. For I made it through AppWizard
and just include one more head file in its
head file to call DLL.
From: vORtex <tayteckl@comp.nus.edu.sg>
Subject: Re: [vc++]error C2059
Date: 19 Jan 1999 07:54:13 GMT

You may want to try this.

At Settings -> C/C++ ->Precompiled Headers, click "Automatic use..."
instead of "Use precompiled..." 

From: pAtHy <leesingc@comp.nus.edu.sg>
Subject: [c++] parameter problem
Date: 25 Jan 1999 07:39:07 GMT

in c++, suppose a function has this prototype :
void boogie(SomeType& temp);

then, how do i pass in the parameter, assuming that in the calling
program, i've declared a variable MyVar, which is of the type 
SomeType?
From: Chong Chee Yong <chongch1@comp.nus.edu.sg>
Subject: Re: [c++] parameter problem
Date: 25 Jan 1999 09:04:46 GMT

SomeType MyVar;
boogie (MyVar);
From: valk <ngkaboon@comp.nus.edu.sg>
Subject: Re: [c++] parameter problem
Date: 25 Jan 1999 13:15:21 GMT

: thanks. btw, what's the difference betw having and not having an
: '&' in the prototype's parameter?

call by reference vs call by value.

From: BlUrgIrl <mohweili@comp.nus.edu.sg>
Subject: C programming..
Date: 26 Jan 1999 06:15:20 GMT

how to "tokenize" a long string of sentence in C program..or there 
isn't any methods in the first place..??
any short and sweet solutions??
From: CyKe <leongkwo@comp.nus.edu.sg>
Date: 26 Jan 1999 07:09:21 GMT

man strtok.
From: Dunno <tohtahwe@comp.nus.edu.sg>
Date: 26 Jan 1999 10:10:56 GMT

>man strtok
bit of warning. destroys the original string. dun like it.
From: JnZ <jouweihu@comp.nus.edu.sg>
Date: 26 Jan 1999 11:20:14 GMT

Dunno <tohtahwe@comp.nus.edu.sg> wrote:
-> dunno why i copy to another string (strcpy, not put another ptr to
->original str), original str still gone.

You need an extra pointer to point to whatever tokens that was returned. 
The original pointer must be kept(if you don't want to lose the string).

From: BoChap 3*7=21 <chiachie@comp.nus.edu.sg>
Subject: [C] How to extract milliseconds?
Date: 27 Jan 1999 06:24:53 GMT

I am trying some random generator function. 

Using srand(time(NULL)), the seed changes only after every second. Is
there anyway i can make the seed change after every millisecond?
From: Lee Boon Peng <leebp@comp.nus.edu.sg>
Date: 27 Jan 1999 06:33:49 GMT

man gettimeofday

But why would you want to keep seeding the random function?
From: pAtHy <leesingc@comp.nus.edu.sg>
Date: 27 Jan 1999 12:05:54 GMT

to generate random numbers, u dun have to make the seed change 
every millisecond. u just do it once at the beginning of the
program and that'll be enough.

From: pAtHy <leesingc@comp.nus.edu.sg>
Subject: [VC++] Horiz Scrollbar for Listbox
Date: 3 Feb 1999 01:29:18 GMT

I've got this problem with listboxes in VC++. 

I created a listbox with the WS_HSCROLL and WS_VSCROLL flags 
included. The vertical scrollbar comes on automatically as more 
and more strings are added to the listbox. 

However, the horizontal scrollbar just wouldn't appear, no matter 
how long a string I add. Anyone knows what's the problem? 
From: VeTeRaN BoDyGuArD <chuawei1@comp.nus.edu.sg>
Date: 3 Feb 1999 03:35:38 GMT

u must set the length to scroll using LB_SETHORIZONTALEXTENT
Check out the helpf for that and GetTextExtentPoint32

From: Lin Dakun <lindakun@comp.nus.edu.sg>
Subject: winsock.h in VC++
Date: 4 Feb 1999 03:22:11 GMT

does any one know how to make winsock.h work with a console application in
VC++? the problem is that we cannot even allocate a socket, not to
mention others like getservbyname. we are using C only without MFC (for
cgi). what are the things we need to change, e.g. wsock32.lib in project
setting, etc. 

our code for allocation of allocating of socket is as follows:

SOCKET s;
s = socket(AF_INET, SOCK_STREAM, 0);

this always returns INVALID_SOCKET to s.

these are the headers, some may not be useful but included just in case:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <winsock.h>

main(){
	SOCKET s;
	s = socket(AF_INET, SOCK_STREAM, 0);
...
}

i used VC++ to trace the value of s. s gets INVALID_SOCKET (instead of -1
cause declared as SOCKET), so the connect() fails, of course, regardless
of how i initialized the system.

besides the socket() problem, calls like getservbyname("smtp", "tcp")
and gethostbyname("www.nus.edu.sg") don't work either. I had to use "25"
for port number and "137.132.xx.xx" format for hosts.
From: JnZ <jouweihu@comp.nus.edu.sg>
Date: 4 Feb 1999 12:06:24 GMT

Does WSAStartup() have anything to do with it?
From: Lin Dakun <lindakun@comp.nus.edu.sg>
Date: 4 Feb 1999 14:36:26 GMT

yeah, the problem was with WSAStartup(). Alvin Toh emailed me earlier on
regarding this, and I have been busy testing the program (a lot of bugs
since first time testing the netwk part). thanks to all the help!!!

just curious, why must winsock be initialized while socket (unix) doesn't?
all the books I could find from the library are using MFC/C++, and our
system didn't have the MSDN installed. that's why we didn't realize the
WSAStartup() problem.
From: JnZ <jouweihu@comp.nus.edu.sg>
Date: 5 Feb 1999 01:22:30 GMT

->just curious, why must winsock be initialized while socket (unix) doesn't?

sockets are part of the unix kernel while winsock is a dll that needs to
be loaded first? I dunno. *8)

From: Hong Jin Bao <chewkian@comp.nus.edu.sg>
Subject: How to read ...
Date: 8 Feb 1999 05:52:01 GMT

How do I read in an int from a file using 'C' or 'C++' without
using fscanf? Thanks :)
From: VeTeRaN BoDyGuArD <chuawei1@comp.nus.edu.sg>
Date: 8 Feb 1999 08:12:54 GMT

fread??
From: Hong Jin Bao <chewkian@comp.nus.edu.sg>
Date: 8 Feb 1999 08:55:34 GMT

Juz found that fgets works well :) Thanks anyway :))))

Subject: VC++ Calling default browser

I am doing some VC++ programming, just wondering is there any simple
way to call the default browser to display a URL from my program ?
From: JnZ <jouweihu@comp.nus.edu.sg>
Date: 8 Feb 1999 14:38:43 GMT

Maybe something like exec("start yourURL")?

From: VeTeRaN BoDyGuArD <chuawei1@comp.nus.edu.sg>
Subject: C lib??
Date: 9 Feb 1999 15:32:35 GMT

Hi, I am programming Win32 in Visual C++. All my files are
in .cpp. Is it possible for me to use the libraries compiled
from .c files? I tried linking the *.lib in the 
Project->settings->links. However, there are still unresolved
symbols errors during linking. However it will work if i use
.c for all my file extensions. But I do not wish to change
my file extensions. How??
From: LockSmith <woontong@comp.nus.edu.sg>
Date: 9 Feb 1999 16:02:02 GMT

this is due to the different name mangling used in C and C++.
you have to tell the compiler which parts are C when you're 
compiling. eg.

extern "C" {
	#include "my_C_library_header.h"
}

From: S K Ting <tingshan@comp.nus.edu.sg>
Subject: Query on gluPickMatrix
Date: 9 Feb 1999 01:09:05 GMT

I have a question abt gluPickMatrix( x, y, w, h, viewport);
If I am not wrong, x and y are the pixel coordinates of the
window and w and h are the size of the picking area (also in
pixel).

viewport actually contains the coordinates of the lower left
corner of the viewport and its respective height and width.

Hope I am correct in the above.

My ques is:
1. Is the coordinates of the viewport also in pixel?

2. If viewport is not the entire window, do I have to
do some translations to change x and y with respect
to the lower left corner of the viewport and not the
window?

Thanks for any help rendered.