Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Colombo
RidhMathraa ’26 🎶✨
Tmadhusanka
Updated:
Wednesday at 11:58 PM
Ad icon
Colombo
PXN V10 Pro Direct Drive Racing Wheel (Under Warranty)
Abdur Rahman
Updated:
Wednesday at 10:23 PM
Ad icon
USDT ණය සේවාව - USDT Loan Service
පුරවැසියා
Updated:
Wednesday at 4:54 PM
Ad icon
🎮 INDIAN PSN GIFT CARDS AVAILABLE NOW! 🎮
madukaperera
Updated:
Tuesday at 12:57 PM
🚀 Google AI PRO – 18 Months | Rs. 850 Only
lkkolla
Updated:
Monday at 4:56 PM
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Help
C Programming Help !
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="Sudantha_s" data-source="post: 3854745" data-attributes="member: 17752"><p>Im entering data to a Strcure in C program <img src="/styles/default/xenforo/smilies/default/happy.gif" class="smilie" loading="lazy" alt=":)" title="Happy :)" data-shortname=":)" /> .. but da data overight in same location <img src="/styles/default/xenforo/smilies/default/sad.gif" class="smilie" loading="lazy" alt=":(" title="Sad :(" data-shortname=":(" /> .. pls help !</p><p></p><p></p><p>[CODE]#include<stdio.h></p><p>#include<conio.h></p><p>#include <stdlib.h></p><p>#include<string.h></p><p></p><p>#define MAX 5</p><p></p><p> //contact strcutre</p><p> typedef struct contact</p><p> {</p><p> char first[25];</p><p> char last[25];</p><p> double num[10];</p><p></p><p> };</p><p></p><p></p><p> contact c[5];</p><p> contact arr[MAX];</p><p></p><p>//function define</p><p>void add_new();</p><p>void edit();</p><p>void menu();</p><p>void view();</p><p>void search();</p><p></p><p>// ***BEGIN OF ADD CONTACT***</p><p>void add_new()</p><p>{</p><p></p><p> up:</p><p> char input1;</p><p> //contact c[5];</p><p> clrscr();</p><p> for(int i=0;i<MAX;i++)</p><p> {</p><p> printf("\n\n\tAdd a new contact\n");</p><p> printf("\n Enter the First Name :");</p><p> fflush(stdin);</p><p> gets(c[i].first);</p><p> printf("\nEnter Surname :");</p><p> gets(c[i].last);</p><p> fflush(stdin);</p><p> printf("\n Enter the Number :");</p><p> scanf("%d",&c[i].num);</p><p> fflush(stdin);</p><p> clrscr();</p><p> printf("\nName : %s%s%s",c[i].first," ",c[i].last);</p><p> printf("\nNumber : %s",c[i].num);</p><p> //menu:</p><p> printf("\n\n\tDo you Want to Add More Contacts (Y/N) : ");</p><p> scanf("%s",&input1);</p><p> //scan user value</p><p> fflush(stdin);</p><p> if(input1=='y')</p><p> {</p><p> clrscr();</p><p> printf("\n\n\tData Saved !");</p><p> goto up;</p><p> }</p><p></p><p> else if (input1=='n')</p><p> {</p><p> clrscr();</p><p> menu();</p><p></p><p> }</p><p> else</p><p> {</p><p> clrscr();</p><p> printf("\n\tInvalid Input!");</p><p> // goto menu;</p><p> }</p><p></p><p></p><p> }</p><p></p><p></p><p>}</p><p></p><p>//***END OF ADD FUNCTION***</p><p></p><p>//***BEGIN SHOW ALL CONTACTS FUNCTION</p><p>void view()</p><p>{</p><p></p><p></p><p></p><p>for(int j=0;j<MAX;j++)</p><p> {</p><p> //view contacts</p><p> printf("\n Name : %s%s%s",c[j].first," ",c[j].last);</p><p> printf("\n Number %s\n",c[j].num);</p><p> }</p><p></p><p></p><p>}</p><p>//*** END OF ADD FUNCTION</p><p></p><p>//**BEGIN SEARCH FUNCTION**</p><p>void search(void)</p><p>{</p><p></p><p>char name_s[25];</p><p>int i;</p><p></p><p></p><p>clrscr();</p><p>printf("\n\n\t Search a Contact");</p><p></p><p>printf("\n\nEnter a Name to Search : ");</p><p>gets(name_s);</p><p>fflush(stdin);</p><p></p><p>for(i=0;i<5;i++)</p><p> {</p><p> if (strcmp(c[i].first,name_s))</p><p> {</p><p> printf("Found !");</p><p> break;</p><p> }</p><p> else</p><p> {</p><p> printf("Not FOund !");</p><p> break;</p><p></p><p> }</p><p> }</p><p></p><p></p><p></p><p></p><p>}</p><p></p><p></p><p></p><p></p><p>//**END OF SEARCH FUNCTION</p><p></p><p></p><p></p><p></p><p></p><p></p><p>//main</p><p>void main()</p><p>{</p><p></p><p> contact c[5];</p><p></p><p> menu();</p><p></p><p></p><p></p><p>}</p><p></p><p></p><p>//menu fuction</p><p>void menu()</p><p>{</p><p></p><p> int input;</p><p> menu:</p><p> printf("\n\t[1] Create My Phone Book\n");</p><p> printf("\n\t[2] Modify Contact\n");</p><p> printf("\n\t[3] Display All Records\n");</p><p> printf("\n\t[4] Search a Number\n");</p><p> printf("\n\t[5] Exit\n");</p><p></p><p> //user select option</p><p> printf("\n\n Enter the Choice : ");</p><p> scanf("%d",&input);</p><p> fflush(stdin);</p><p></p><p> if (input==1)</p><p> {</p><p> //load add</p><p> add_new();</p><p></p><p> }</p><p></p><p> else if (input==2)</p><p> {</p><p> //modfy</p><p> }</p><p> else if (input==3)</p><p> {</p><p> clrscr();</p><p> view();</p><p> }</p><p> else if (input==4)</p><p> {</p><p> //search</p><p> search();</p><p></p><p> }</p><p> else if(input==5)</p><p> {</p><p> abort();</p><p> }</p><p></p><p> else</p><p> {</p><p> printf("Invalid Error !");</p><p> menu;</p><p> }</p><p></p><p></p><p>}[/CODE]</p></blockquote><p></p>
[QUOTE="Sudantha_s, post: 3854745, member: 17752"] Im entering data to a Strcure in C program :) .. but da data overight in same location :( .. pls help ! [CODE]#include<stdio.h> #include<conio.h> #include <stdlib.h> #include<string.h> #define MAX 5 //contact strcutre typedef struct contact { char first[25]; char last[25]; double num[10]; }; contact c[5]; contact arr[MAX]; //function define void add_new(); void edit(); void menu(); void view(); void search(); // ***BEGIN OF ADD CONTACT*** void add_new() { up: char input1; //contact c[5]; clrscr(); for(int i=0;i<MAX;i++) { printf("\n\n\tAdd a new contact\n"); printf("\n Enter the First Name :"); fflush(stdin); gets(c[i].first); printf("\nEnter Surname :"); gets(c[i].last); fflush(stdin); printf("\n Enter the Number :"); scanf("%d",&c[i].num); fflush(stdin); clrscr(); printf("\nName : %s%s%s",c[i].first," ",c[i].last); printf("\nNumber : %s",c[i].num); //menu: printf("\n\n\tDo you Want to Add More Contacts (Y/N) : "); scanf("%s",&input1); //scan user value fflush(stdin); if(input1=='y') { clrscr(); printf("\n\n\tData Saved !"); goto up; } else if (input1=='n') { clrscr(); menu(); } else { clrscr(); printf("\n\tInvalid Input!"); // goto menu; } } } //***END OF ADD FUNCTION*** //***BEGIN SHOW ALL CONTACTS FUNCTION void view() { for(int j=0;j<MAX;j++) { //view contacts printf("\n Name : %s%s%s",c[j].first," ",c[j].last); printf("\n Number %s\n",c[j].num); } } //*** END OF ADD FUNCTION //**BEGIN SEARCH FUNCTION** void search(void) { char name_s[25]; int i; clrscr(); printf("\n\n\t Search a Contact"); printf("\n\nEnter a Name to Search : "); gets(name_s); fflush(stdin); for(i=0;i<5;i++) { if (strcmp(c[i].first,name_s)) { printf("Found !"); break; } else { printf("Not FOund !"); break; } } } //**END OF SEARCH FUNCTION //main void main() { contact c[5]; menu(); } //menu fuction void menu() { int input; menu: printf("\n\t[1] Create My Phone Book\n"); printf("\n\t[2] Modify Contact\n"); printf("\n\t[3] Display All Records\n"); printf("\n\t[4] Search a Number\n"); printf("\n\t[5] Exit\n"); //user select option printf("\n\n Enter the Choice : "); scanf("%d",&input); fflush(stdin); if (input==1) { //load add add_new(); } else if (input==2) { //modfy } else if (input==3) { clrscr(); view(); } else if (input==4) { //search search(); } else if(input==5) { abort(); } else { printf("Invalid Error !"); menu; } }[/CODE] [/QUOTE]
Insert quotes…
Verification
Winadiyakata thappara keeyak tibeda?
Post reply
Top
Bottom