Note that there are some explanatory texts on larger screens.

plurals
  1. POIn my program what is the difference between Record* and Databse*?
    primarykey
    data
    text
    <p>I am using Dev C++ compiler. So, what's wrong in here, i am getting errors in the addRecord Module.</p> <p>The compile log :</p> <pre><code>Compiler: Default compiler Executing g++.exe... g++.exe "C:\SAI,MANI\test_add(09.03.2013).cpp" -o "C:\Users\Ravitheja\Desktop\C and C++\Projects\SAI,MANI\test_add(09.03.2013).exe" -O3 -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -g3 C:\SAI,MANI\test_add(09.03.2013).cpp: In function `void addRecord(Record*)': C:\SAI,MANI\test_add(09.03.2013).cpp:151: error: using typedef-name `Record' after `struct' C:\SAI,MANI\test_add(09.03.2013).cpp:151: error: cannot convert `Record*' to `Database*' in assignment C:\SAI,MANI\test_add(09.03.2013).cpp:153: error: expected primary-expression before '*' token C:\SAI,MANI\test_add(09.03.2013).cpp:153: error: expected primary-expression before ')' token C:\SAI,MANI\test_add(09.03.2013).cpp:153: error: expected `;' before "malloc" C:\SAI,MANI\test_add(09.03.2013).cpp:154: error: cannot convert `Record*' to `Database*' in assignment C:\SAI,MANI\test_add(09.03.2013).cpp: In function `void viewRecords(Record*)': C:\SAI,MANI\test_add(09.03.2013).cpp:180: error: cannot convert `Database*' to `Record*' in assignment C:\SAI,MANI\test_add(09.03.2013).cpp: In function `int getDate(date*)': C:SAI,MANI\test_add(09.03.2013).cpp:187: error: conversion from `date*' to non-scalar type `date' requested Execution terminated </code></pre> <p>particularly in this line ,</p> <blockquote> <p><code>x-&gt;next = (Record*)malloc(sizeof(struct Record));</code></p> </blockquote> <p>i am getting an error : cannot convert 'Record*' to ' Database*' in assignment, but what is the difference between Record and Database, as i have typedef-ed them.</p> <p>I have not written all the modules yet, i just wanted to test my addRecord() and viewRecords() , but it's not working. How to correct these errors ?</p> <pre><code>#include&lt;iostream&gt; #include&lt;conio.h&gt; #include&lt;stdlib.h&gt; #include&lt;malloc.h&gt; using namespace std; // global declarations and function prototypes.... const int TRUE = 1,FALSE = 0,SUCCESS = 1; const int SUBJECTS = 3; typedef char String[25]; // date structure , a better way to store dates. struct date { int day,month,year; }; // Database structure , the main double linked list which stores all the information. typedef struct DataBase { String Name,FatherName,Address,Hometown; float Marks[SUBJECTS],Total,Percentage; date DOB; long int RegNo,PhoneNumber; struct Database *previous; // the addresses of the next and previous nodes in the dll. struct Database *next; }Record; int main(); int menu(); // for displaying menu. void process(int,Record*); // for processing the menu. void addRecord(Record*); // for adding a record. void delRecord(Record*); // for deleting a record. void modRecord(Record*); // for modifying values of a record. void sortRecords(Record*); // for sorting records. void filterRecords(Record*); // for filtering records. void searchRecords(Record*); // for searching a record. void viewRecords(Record*); // for viewing records (all). int getDate(date*); // for getting input for a date. void copyDate(date,date*); // for copying two date variables. int checkDate(date); // for checking wether a given date is correct. char *toString(int); // for displaying month name given the month number. void copyRecord(Record*,Record*); // for copying contents of one record into another. // main function... int main() { Record *r; r = (Record*) malloc (sizeof(Record)); r-&gt;next = NULL; r-&gt;previous = NULL; while(1) { process(menu(),r); } } // the menu function. int menu() { static int choice; cout&lt;&lt;"\n\t\t\t Menu"; cout&lt;&lt;"\n\t\t\t 1.Add Records "; cout&lt;&lt;"\n\t\t\t 2.Delete Records"; cout&lt;&lt;"\n\t\t\t 3.Modify Records"; cout&lt;&lt;"\n\t\t\t 4.Sort Records"; cout&lt;&lt;"\n\t\t\t 5.Filter Records"; cout&lt;&lt;"\n\t\t\t 6.Search Records"; cout&lt;&lt;"\n\t\t\t 7.View Records"; cout&lt;&lt;"\n\t\t\t 8.Exit"; cout&lt;&lt;"\n\t\t\t YOUR CHOICE : "; cin&gt;&gt;choice; if(choice&gt;=1 &amp;&amp; choice&lt;=7) return choice; else if(choice == 8) exit(0); else { cout&lt;&lt;"\n Sorry, that's an invalid choice."; cout&lt;&lt;"\n Please Try Again."; menu(); } } void process(int choice,Record *r) { switch(choice) { case 1: addRecord(r); break; case 2: delRecord(r); break; case 3: modRecord(r); break; case 4: sortRecords(r); break; case 5: filterRecords(r); break; case 6: searchRecords(r); break; case 7: viewRecords(r); break; } } void addRecord(Record *x) { date *t; t = (date*) malloc ( sizeof(date) ); fflush(stdin); Record *temp; temp = (Record*) malloc ( sizeof(Record) ); cout&lt;&lt;"\n Enter the following details ..... "&lt;&lt;endl; cout&lt;&lt;"\n Name : "; gets(temp-&gt;Name); cout&lt;&lt;"\n Father's Name : "; gets(temp-&gt;FatherName); cout&lt;&lt;"\n Address :"; gets(temp-&gt;Address); cout&lt;&lt;"\n Hometown : "; gets(temp-&gt;Hometown); cout&lt;&lt;"\n Register Number : "; cin&gt;&gt;temp-&gt;RegNo; temp-&gt;Total = 0; for(int i=0;i&lt;SUBJECTS;i++) { cin&gt;&gt;temp-&gt;Marks[i]; temp-&gt;Total += temp-&gt;Marks[i]; } temp-&gt;Percentage = temp-&gt;Total/SUBJECTS; cout&lt;&lt;"\n Total Marks : "&lt;&lt;temp-&gt;Total; cout&lt;&lt;"\n\n Percentage : "&lt;&lt;temp-&gt;Percentage; if(getDate(t) == SUCCESS) // trick! copyDate(temp-&gt;DOB,t); x-&gt;next = (Record*)malloc(sizeof(struct Record)); copyRecord(x,temp); temp-&gt;previous = (Record*)malloc(struct Database); temp-&gt;previous = x; temp-&gt;next = NULL; return; } void viewRecords(Record *x) { if(x-&gt;next == NULL &amp;&amp; x-&gt;previous == NULL) { cout&lt;&lt;"\n There are no records to view."; cout&lt;&lt;"\n Please Add some records and then try again!"; return; } do { cout&lt;&lt;"\n Name : "&lt;&lt;x-&gt;Name; cout&lt;&lt;"\n Father's Name : "&lt;&lt;x-&gt;FatherName; cout&lt;&lt;"\n Address : "&lt;&lt;x-&gt;Address; cout&lt;&lt;"\n Hometown : "&lt;&lt;x-&gt;Hometown; cout&lt;&lt;"\n Register Number : "&lt;&lt;x-&gt;RegNo; for(int i=0;i&lt;SUBJECTS;i++) cout&lt;&lt;"\n Mark "&lt;&lt;i+1&lt;&lt;" : "&lt;&lt;x-&gt;Marks[i]; cout&lt;&lt;"\n Total Marks : "&lt;&lt;x-&gt;Total&lt;&lt;endl; cout&lt;&lt;"\n Percentage : "&lt;&lt;x-&gt;Percentage; cout&lt;&lt;"\n Date Of Birth : "&lt;&lt;x-&gt;DOB.day&lt;&lt;"th"&lt;&lt;toString(x-&gt;DOB.month)&lt;&lt;" "&lt;&lt;x-&gt;DOB.year; if(x-&gt;next == NULL) break; }while((x=x-&gt;next)!=NULL); } int getDate(date *t) { cout&lt;&lt;"\nDate of birth (dd:mm:yyyy) : "; scanf("%d:%d:%d",&amp;t-&gt;day,&amp;t-&gt;month,&amp;t-&gt;year); if(checkDate(t) == SUCCESS) return SUCCESS; else { cout&lt;&lt;"\n Sorry, that's not a valid Date."; cout&lt;&lt;"\n Please Try Again,"&lt;&lt;endl; getDate(t); } } void copyDate(date d1,date *d2) { d1.day = d2-&gt;day; d1.month = d2-&gt;month; d1.year = d2-&gt;year; return; } int checkDate(date *x) { int leap = (x-&gt;year%4==0)?TRUE:FALSE; if( ( x-&gt;day&lt;=0 || x-&gt;day &gt; 31 ) || (x-&gt;month&gt;12 || x-&gt;month&lt;=0) || (x-&gt;year&lt;1900 || x-&gt;year &gt; 2008) ) return FALSE; else if(leap == TRUE &amp;&amp; x-&gt;month == 2 &amp;&amp; (x-&gt;day&gt;29)) return FALSE; else if(leap == FALSE &amp;&amp; x-&gt;month == 2 &amp;&amp; (x-&gt;day&gt;28)) return FALSE; else if( (x-&gt;month == 4 || x-&gt;month == 6 || x-&gt;month == 9 || x-&gt;month == 11) &amp;&amp; x-&gt;month &gt;= 31 ) return FALSE; else return TRUE; } char *toString(int m) { char *t = (char*) malloc (sizeof(char)*4); switch(m) { case 1 : t = "Jan"; break; case 2 : t = "Feb"; break; case 3 : t = "Mar"; break; case 4 : t = "Apr"; break; case 5 : t = "May"; break; case 6 : t = "Jun"; break; case 7 : t = "Jul"; break; case 8 : t = "Aug"; break; case 9 : t = "Sep"; break; case 10 : t = "Oct"; break; case 11 : t = "Nov"; break; case 12 : t = "Dec"; break; } return t; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload