|
for example:
/* ---------- */
/* premier2.c */
/* ---------- */
#include <stdio.h>
#include <math.h>
main()
{
int nb, diviseur1, diviseur2,reste ;
int trouve,i ,racinecar,limite ;
int nb_iterations=1;
printf("Entrez un Nombre :");
scanf("%d",&nb);
/* partie entiere de la racine carre+1 */
limite=sqrt(nb)+1;
trouve=0 ;
if (nb != 2) /* 2 est premier */
{
/* on retire le cas des nombres pairs */
reste=nb%2 ;
if (reste == 0)
{
trouve=1 ;
/* on memorise les diviseurs */
diviseur1=2 ;
diviseur2=nb/2 ;
}
else
{
/* teste tous les diviseurs impairs */
i=3;
while ( (! trouve) && (i<=limite) )
{
nb_iterations++;
reste= nb%i ;
if (reste == 0)
{
trouve=1 ;
/* on memorise les diviseurs */
diviseur1=i ;
diviseur2=nb/i ;
}
i+=2 ;
}
}
}
if (trouve)
{
printf("%d n'est pas premier !\n",nb);
printf("il est divisible par %d et %d\n",diviseur1,diviseur2);
}
else
{
printf("%d est un nombre PREMIER !\n",nb);
}
printf("RŽsultat obtenu en %d itŽrations\n",nb_iterations);
}
result:
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/premier2.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
premier2.exe - 2 error(s), 0 warning(s)
|
|
|
|
|
What type of project is this .c file a part of? What preprocessor definitions do you have defined? You need _WIN32 and _CONSOLE at a minimum. Also be sure /subsystem:console is one of the linker options.
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
honestly here I am a bit lost....
well ...here is an example of a typical c file, complete!
I have VC++ 6.0 standard edition.
But I am really a newbie in converting c files on VC++ 6.0
Maybe you could tell me how to proceed and which changes?
Usually, I click on the file and immediatelly the VC++ appears..
Thanks,
T
-------->example of a comple c file
/* ------------------ */
/* liste_structure2.c */
/* ------------------ */
#include <stdio.h>
#include <stdlib.h>
#define TAILLE_NOM 20
#define TAILLE_PRENOM 30
/* --- sous-programmes --- */
void saisie() ;
void affichage() ;
struct etudiant *recherche(char nom_recherche[]);
void modification() ;
/* --- variables globales --- */
struct etudiant {
struct etudiant *pred ;
char nom[TAILLE_NOM] ;
char prenom[TAILLE_PRENOM];
int age ;
struct etudiant *succ ;
} ;
struct etudiant *debut_liste,*fin_liste;
int nbeleves=0;
/* ===== PROGRAMME ===== */
main()
{
char choix=' ', ch_saisie[20];
debut_liste = NULL;
fin_liste = NULL;
while (choix!='q')
{
printf("-1- Saisie d'une liste\n");
printf("-2- Affichage\n");
printf("-3- Modification d'un Žlve\n");
printf("-q- quitter\n");
printf("Choix : ");
scanf("%s",ch_saisie);
choix=ch_saisie[0];
switch(choix)
{
case '1' : saisie();
break;
case '2' : affichage();
break;
case '3' : modification();
break;
case 'q' : printf("Au revoir\n");
break;
default : printf("Choix non valide\n");
break;
}
}
}
/* === chargement de la liste === */
void saisie()
{
struct etudiant *nouv_eleve,*eleve_actuel;
int termine = 0 ;
/* --- boucle de saisie --- */
while (! termine)
{
nouv_eleve = malloc(sizeof(struct etudiant));
printf("Entrez un nom ( nom=fin pour terminer):");
scanf("%s",nouv_eleve->nom);
termine=((strcmp(nouv_eleve->nom,"fin"))==0) ;
if (! termine) /* saisie du reste */
{
printf("Entrez un prŽnom:") ;
scanf("%s",nouv_eleve->prenom);
printf("Entrez un ‰ge:") ;
scanf("%d",&(nouv_eleve->age));
nouv_eleve->pred=NULL ;
nouv_eleve->succ=NULL ;
if (debut_liste == NULL)
{ /* Liste vide. C'est le seul element */
debut_liste = nouv_eleve ;
fin_liste = nouv_eleve ;
}
else
{ /* ajout en fin de liste */
fin_liste->succ = nouv_eleve ;
nouv_eleve->pred = fin_liste ;
fin_liste = nouv_eleve ;
}
/* on compte le nombre d'eleves */
nbeleves++ ;
}
}
}
/* === affichage === */
void affichage()
{
struct etudiant *eleve_actuel;
/* --- boucle d'affichage --- */
printf("--- %d Žlves ---\n",nbeleves);
eleve_actuel=debut_liste ;
while (eleve_actuel != NULL )
{
printf("%-10s",eleve_actuel->nom) ;
printf("%-10s",eleve_actuel->prenom);
printf("%3d\n",eleve_actuel->age) ;
eleve_actuel = eleve_actuel->succ ;
}
}
/* === recherche sur critere === */
struct etudiant *recherche(char nom_recherche[])
{
int trouve=0;
struct etudiant *eleve_actuel;
/* --- boucle de recherche --- */
eleve_actuel=debut_liste ;
while ((!trouve) && (eleve_actuel != NULL))
{
trouve=(strcmp(eleve_actuel->nom,nom_recherche)==0);
if (!trouve)
eleve_actuel = eleve_actuel->succ ;
}
if (!trouve)
eleve_actuel = NULL ;
return eleve_actuel ;
}
/* === modification === */
void modification()
{
char nom_modif[TAILLE_NOM];
struct etudiant *eleve_modif;
/* saisie du nom a modifier */
printf("Nom de l'Žlve:");
scanf("%s",nom_modif);
/* recherche */
eleve_modif=recherche(nom_modif);
if (eleve_modif!=NULL)
{
/* affichage */
printf("%-10s",eleve_modif->nom) ;
printf("%-10s",eleve_modif->prenom);
printf("%3d\n",eleve_modif->age) ;
/* modifications */
printf("Nouveau Nom : ");
scanf("%s",eleve_modif->nom);
printf("Nouveau Prenom : ");
scanf("%s",eleve_modif->prenom);
printf("Nouvel Age : ");
scanf("%d",&(eleve_modif->age));
}
else
printf("%s non trouvŽ\n",nom_modif);
}
|
|
|
|
|
There's no need to post all of this code. Most, if not all, of it is irrelevant. Open Visual Studio. Select New from the File menu. Click the Projects tab. Near the bottom of the list, select Win32 Console Application, give the project a name, and click the OK button. On the Step 1 of 1 dialog box, select one of the four radio buttons (e.g., A "Hello World" application). Click the Finish button. Click the OK button. Now open the main .cpp file and paste your code into it, overriding whatever is there. Press F7 to compile and link. Does that help?
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
yes,
but there an error message:
Compiling...
ooooo.cpp
c:\documents and settings\atvd\desktop\new folder00ppp\ooooo\ooooo.cpp(161) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.
ooooo.exe - 1 error(s), 0 warning(s)
and when clicking on the error message , it shows the end, after the last }
maybe I should ad a main...? how...?
Thanks a lot!
|
|
|
|
|
The default compiler options needs a pre compiled header.
You should add #include "stdafx.h" to the begining of your code.
Another solution is to remove this option from your compile directive.
Its been a long time since I used VC++6.0 but I think this is what you should do.
1. open project properties from menu or press Alt+F7
2. select the file ooooo.cpp in the tree view
3. select compile options in the right form.
4. select pre compiled header from the combo box
5. set the radio button to disable the use of pre-compiled headers.
codito ergo sum
|
|
|
|
|
same problem.....
C:\Documents and Settings\atvd\Desktop\New Folder00ppp\uuuu\uuuu.cpp(31) : warning C4508: 'main' : function should return a value; 'void' return type assumed
|
|
|
|
|
thierrypp wrote: more generally, can a common C programme be compiled on a Visual C++ 6.0 compiler?
Yes. But...
Visual C++ 6 applies a C++ compiler to files with a .cpp extension, and a C compiler to files with a .c extension.
Do your source files have a .c extension?
What errors are you getting?
|
|
|
|
|
yes, files with a c extension *.c
for example: and result of compilation..
for example:
/* ---------- */
/* premier2.c */
/* ---------- */
#include
#include
main()
{
int nb, diviseur1, diviseur2,reste ;
int trouve,i ,racinecar,limite ;
int nb_iterations=1;
printf("Entrez un Nombre :");
scanf("%d",&nb);
/* partie entiere de la racine carre+1 */
limite=sqrt(nb)+1;
trouve=0 ;
if (nb != 2) /* 2 est premier */
{
/* on retire le cas des nombres pairs */
reste=nb%2 ;
if (reste == 0)
{
trouve=1 ;
/* on memorise les diviseurs */
diviseur1=2 ;
diviseur2=nb/2 ;
}
else
{
/* teste tous les diviseurs impairs */
i=3;
while ( (! trouve) && (i<=limite) )
{
nb_iterations++;
reste= nb%i ;
if (reste == 0)
{
trouve=1 ;
/* on memorise les diviseurs */
diviseur1=i ;
diviseur2=nb/i ;
}
i+=2 ;
}
}
}
if (trouve)
{
printf("%d n'est pas premier !\n",nb);
printf("il est divisible par %d et %d\n",diviseur1,diviseur2);
}
else
{
printf("%d est un nombre PREMIER !\n",nb);
}
printf("RŽsultat obtenu en %d itŽrations\n",nb_iterations);
}
result:
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/premier2.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
premier2.exe - 2 error(s), 0 warning(s)
|
|
|
|
|
hi,
when code compiled is with a c++ compiler the code needs to be c++ compiler compatible.
C code is almost 90% compliant to c++ code, but there are some distinct issues that one must
know off.
thierrypp wrote: LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
this error means that the compiler didn't find the main entry point of your code.
you did write
#include <something>
main()
{
you did forget to add a return value for your main function. Some C compilers automatically asume that you meant to write int main(void) but most C++ compilers don't do this automatic translation. Thats way the function main didn't compile hence there is no function to link too -> Unresolved external
The rest of the code looks fine.
codito ergo sum
|
|
|
|
|
yes, right,
#include <stdio.h>
#include <stdlib.h>
but I do not get how to deal with main,
what should be modified?
Thanks,
T.
|
|
|
|
|
hi,
try to change main() to void main()
codito ergo sum
|
|
|
|
|
again error:
C:\Documents and Settings\atvd\Desktop\New Folder00ppp\wwww\wwww.cpp(72) : error C2440: '=' : cannot convert from 'void *' to 'struct etudiant *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
Error executing cl.exe.
wwww.exe - 1 error(s), 0 warning(s)
|
|
|
|
|
BadKarma wrote: ...but most C++ compilers don't do this automatic translation.
Visual Studio v6 handles this just fine. He is doing something else wrong as his code compiles fine as a .c file or a .cpp file. I suspect it's the type of project he chose.
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Visual Studio v6 handles this just fine. He is doing something else wrong as his code compiles fine as a .c file or a .cpp file. I suspect it's the type of project he chose.
When I tested the code i wrongfully pasted the code in a .cpp file which led to the unresolved error which I mentioned. I do however used VS2005 to test. When renamed to a .c file everything compiles and links without a problem.
Sorry to add up the confusion
codito ergo sum
|
|
|
|
|
|
thank you...but I turned it and tested it.....same ..errors
listen, I do not want to abuse too much...
my mail is
thierrypp@yahoo.com
if you want, I will send you a typical set of files and you could send me screenshots?
I would be very grateful if you could.
I am working on Visual C++ 6.0 with standard edition provided with Ivor Horton book, and indeed I made a lot of successful applications with VC++ 6.0.
But with C.....I followed before your link and after and the problems remains...what a pity!
Thanks a lot!
The big problem is that the company left for several months nobody in charge of managing this and after restructuration, no notes, nothing....only me to deal with...
Best regards and thanks,
Thierry
|
|
|
|
|
a typical example, no *.h files
/* ---------------------- */
/* structure_en_globale.c */
/* ---------------------- */
#include <stdio.h>
#include <string.h>
/* -- declaration des constantes -- */
#define TAILLE_NOM 20
#define TAILLE_PRENOM 2*TAILLE_NOM
#define MAX_ETUDIANTS 50
struct etudiant {
char nom[TAILLE_NOM] ;
char prenom[TAILLE_PRENOM] ;
int age ;
} ;
/* -- variables globales -- */
int nbeleves=0 ;
struct etudiant tab_eleves[MAX_ETUDIANTS];
/* -- procedures et fonctions -- */
void saisie_eleves();
void affichage() ;
struct etudiant recherche_eleve(char nom_recherche[]);
/* ----------------------------------- */
main()
{
struct etudiant eleve ;
char nom_eleve[TAILLE_NOM] ;
int choix = -1 ;
/* -- boucle d'affichage du menu -- */
while (choix != 0 )
{
printf("\n");
printf(" -1- Saisie d'une liste d'Žlves \n");
printf(" -2- Recherche d'un Žlve \n");
printf(" -3- Affichage de la liste\n");
printf(" -0- FIN\n");
printf("\n");
printf("Choix:");
scanf("%d",&choix);
/* -- selecteur : appel des procedures -- */
switch (choix)
{
case 1 : saisie_eleves();
break ;
case 2 : printf("Entrez le nom de l'Žlve :");
scanf ("%s",nom_eleve);
eleve=recherche_eleve(nom_eleve);
if (! strcmp(eleve.nom,"NON_TROUVE"))
{
printf("Aucun %s trouvŽ\n",nom_eleve);
}
else
{
printf("Nom : %s\n",eleve.nom);
printf("PrŽnom : %s\n",eleve.prenom);
printf("Age : %d\n",eleve.age);
}
break ;
case 3 : affichage();
break ;
case 0 : printf("Au revoir \n");
break ;
default: printf("Erreur de saisie\n");
break;
}
}
}
/* ----------------------------------- */
void saisie_eleves()
{
struct etudiant studtmp ;
int termine ;
termine = 0 ;
/* -- boucle de saisie du tableau des eleves -- */
while (! termine)
{
printf("Entrez un nom (\"fin\" pour terminer):");
scanf("%s",studtmp.nom);
termine=((strcmp(studtmp.nom,"fin"))==0) ;
if (! termine)
{
printf("Entrez un prŽnom:");
scanf("%s",studtmp.prenom);
printf("Entrez un age:");
scanf("%d",&studtmp.age);
tab_eleves[nbeleves]=studtmp ;
nbeleves++ ;
}
}
}
/* ----------------------------------- */
struct etudiant recherche_eleve(char nom_recherche[])
{
struct etudiant studtmp, eleve_retour={"NON_TROUVE","",0};
int trouve, i ;
trouve = 0 ;
i = 0 ;
while ((! trouve) && (i < nbeleves) )
{
studtmp=tab_eleves[i++] ;
trouve=(!(strcmp(studtmp.nom,nom_recherche))) ;
if (trouve)
{
eleve_retour=studtmp ;
}
}
/* -- retourne une structure -- */
return eleve_retour ;
}
/* ----------------------------------- */
void affichage()
{
int i ;
printf("-- Liste des Žtudiants --\n");
for (i=0 ; i < nbeleves ; i++)
{
printf("%10s ",tab_eleves[i].nom);
printf("%10s ",tab_eleves[i].prenom);
printf("%4d\n", tab_eleves[i].age);
}
}
|
|
|
|
|
sorry,
with:
#include <stdio.h>
#include <stdlib.h>
I am so upset to get it right!
yes, win32 checked and sub console too in the linker option too!
Thanks for your very helpful help.
Knowing finally how to deal with C files on Visual C++ would be of the utmost importance!
Best Regards,
Please, feel free to send me any screenshots.....I welcome you!
T.
Switzerland
|
|
|
|
|
thierrypp wrote: May I know how to work with c files on a visual C++ 6.0 IDE?
Two possibilities:
1. You want to keep the project as a c-project, then you need to change the calling convention in your project settings.
2. You do not care about it being c or c++, then simply rename your .c files .cpp and everything will be ok.
Hope this helps
~RaGE();
|
|
|
|
|
thanks for the informations but in fact, the problem remains......
Maybe if someone knows about Lcc-win 32?
Regards
T.
|
|
|
|
|
Thierry,
I approached this in a methodical way. Follow me and you should be OK:
In Visual C++ 6.0 create a new project. Choose Win 32 Console Application, select a simple application.
Delete the lines:
int main(int argc, char* argv[])
{
return 0;
}
Copy the code in. I used one of the examples you supplied.
Compile: get 5 errors, 1 warning. Looking at what the errors were, I deleted the following two lines which are clearly wrong:
#include
#include
The other three errors are about printf, scanf, strcmp not being recognised. I guess that I need to include some files. I moved the cursor on to the word printf and hit the F1 key. Visual C++ 6.0 gave some information on how to use this function. It also said that it needed the include file <stdio.h>. Same for scanf. For strcmp, Visual C++ 6.0 says that I need to include <syting.h>. So I added the next two lines.
#include <stdio.h>
#include <string.h>
Now there is a warning:
warning C4508: 'main' : function should return a value; 'void' return type assumed
Being just a warning, I could have ignored this. But to do the job properly, as I have been told that main() should return a value, I changed the line
main()
to be:
int main()
and to return a value, I added the following line just before the end of the main() function:
return 0;
Et voila! It compiles. And runs. No problemo, as they say. (And by the way, the source file that Visual C++ created is indeed .CPP, not .C)
Shraddhan
|
|
|
|
|
Oops!
The bit biter swallowed some of my text.
Yhe files to be included are stdio.h and string.h
I guess that because these names were included inside angle brackets they got chopped off. That is preumably the reason why they were missing from the code sample you supplied.
Bon chance,
Shraddhan
|
|
|
|
|
I am writing an GUI using MFC. However, I have one problem. After I type in an Edit Control and then press enter, the GUI will be closed. I want the GUI to remain there after I press enter, so how do I disable this function?
Thanks
|
|
|
|
|
first of u need to give a detail ... r u making a edit ctrl on the modal dialog box ... if yes then the model dlg box takes enter as ONOK event .... u need to catch enter in edit box only..... check for some "want return" kind of setting in resource editor
===============================================================
Want return
Specifies that a carriage return be inserted when the user presses the ENTER key while typing text into a multiline edit-box control. If this style is not specified, pressing the ENTER key has the same effect as pressing the dialog box’s default command button. This style has no effect on a single-line edit-box control. Type: Bool. Default: False
===============================================================
if not the dlg box then pls give more detail
|
|
|
|
|