Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello, I just only want to ask.How to connect MS access database to a C program.See the code below:

C++
#include<stdio.h>
char firstname[20], middlename, lastname[20];
main()
{
   clrscr();
   printf("Enter your First Name: ");scanf("%s",&firstname);
   printf("Enter your Middle Name: ");scanf("%c",&middlename);
   printf("Enter your Last Name: ");scanf("%s",&lastname);
   getch();
}


This is what I want to do for example I have a database file named myname.mdb and in that database there are three fields: fname, mname and lname.

I want the value of firstname pass to fname, middlename pass to mname, and lastname pass to lname
Posted
Updated 4-Sep-11 5:07am
v2

Here's one article explaining basic things: Developing Access 2007 Solutions with Native C or C++[^]
 
Share this answer
 
First thing to do: don't even try like that!
C#
char firstname[20], middlename, lastname[20];
main()
{
clrscr();
printf("Enter your First Name: ");scanf("%s",&firstname);
printf("Enter your Middle Name: ");scanf("%c",&middlename);
printf("Enter your Last Name: ");scanf("%s",&lastname);
getch();
<code>middlename is a single char: i.e. it cannot hold anything returned from scanf except any empty string!
&firstname is a pointer to a pointer to a char. scanf wants a pointer to a char. The same for &lastname

Instead, try this:
C#
#include<stdio.h>
char firstname[20], middlename[20], lastname[20];
main()
   {
   clrscr();
   printf("Enter your First Name: ");scanf("%s",firstname);
   printf("Enter your Middle Name: ");scanf("%c",middlename);
   printf("Enter your Last Name: ");scanf("%s",lastname);
   getch();
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900