ReCom.org
Programming and Web Development Web monks and programmers welcomed

Can some body help me change to C language?

Reply
 
Thread Tools
Cerav Male
Less Junior Member
 
Cerav's Avatar
 
Join Date: Mar 2009
Posts: 117
  #1 Old 01-06-2011 Default Can some body help me change to C language?

Does anyone know how to change this C++ to C? I'm having trouble doing it some pointers would be nice.

Quote:
#include <iostream>
#include <string>
using namespace std;
typedef struct student {
char name[20];
char address[100];
char no[20];
}student;

typedef struct node{
student element;
node* next;
}node;

void print(student a){
cout<<"name : "<<a.name<<endl;
cout<<"address :"<<a.address<<endl;
cout<<"no : "<<a.no<<endl;
}
void printall(node* list){
node* cursor;
for(cursor=list;cursor!=NULL;cursor=cursor->next){
print(cursor->element);
}
}


void search(node* list){
char name[20];
cout<<"search name :";
cin>>name;
node* cursor;
node* follower=NULL;
for(cursor=list;cursor!=NULL;cursor=cursor->next){
if(!strcmp(name,cursor->element.name))
break;
follower=cursor;
}
if(cursor==NULL){
cout<<"student not found"<<endl;
follower=NULL;
}
else{
cout<<"student found :"<<endl;
print(cursor->element);
if(follower==NULL)
follower=cursor;
}
}
node* deletestudent(node* list){//follower-bye-a ---> follower-a
char name[20];
cout<<"delete name :";
cin>>name;
node* cursor;
node* follower=NULL;
for(cursor=list;cursor!=NULL;cursor=cursor->next){
if(!strcmp(name,cursor->element.name))
break;
follower=cursor;
}
if(cursor==NULL){
cout<<"student not found"<<endl;
follower=NULL;
return list;
}
else{
cout<<"student deleted "<<endl;
if(follower==NULL){
follower=cursor->next;
free(cursor);
return follower;
}else{
node* bye=follower->next;
follower->next=follower->next->next;
free(cursor);
return list;
}
}
}
node* insert(node* list){
char name[20];
char address[100];
char no[20];
cout<<"name : ";
cin>>name;
cout<<"address : ";
cin>>address;
cout<<"no : ";
cin>>no;

node* newNode=(node*) malloc(sizeof(node));
strcpy(newNode->element.name,name);
strcpy(newNode->element.address,address);
strcpy(newNode->element.no,no);
newNode->next=list;
return newNode;
}

int main(){
node* list=NULL;
int selection=0;
while(selection!=4){
cin>>selection;
switch(selection){
case 1:list=insert(list); break;
case 2:search(list); break;
case 3:list=deletestudent(list); break;
case 4:break;
case 5rintall(list);break;
}
cout<<endl;
}

}
Cerav is offline   Reply With Quote
markwongsk Male
Developer
 
markwongsk's Avatar
 
Join Date: Nov 2008
Posts: 717
  #2 Old 02-06-2011 Default Re: Can some body help me change to C language?

Quote:
Originally Posted by Cerav View Post
Does anyone know how to change this C++ to C? I'm having trouble doing it some pointers would be nice.
On a quick cursory glance (since I'm in class now), the only part that probably needs changing are the cout cin. The C counterparts are scanf and printf (use the man pages to help you, or just google them). Be careful of buffer overflow exploits though, and use fscanf if you need extra security.
__________________
Per Aspera Ad Astra
markwongsk is offline   Reply With Quote
The Following User Says Thank You to markwongsk For This Useful Post:
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Survey: betrayal of mind?betrayal of body?which1 can u stand by ur spouse? eugenetoh91 Walking Along the Path of Life 3 06-03-2009 11:07 PM
Body Building iQing ReCom Sports Bar 61 31-07-2008 03:25 AM
Courtship Body Language iQing Education 1 20-03-2006 02:06 AM


All times are GMT +8. The time now is 11:50 PM.


Powered by vBulletin® Version 3.7.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

ReCom stands for Reborn Community. It has no affiliation with other organizations that may share the same name. The views expressed in this website solely represent the authors point of view and do not necessarily reflect the views of ReCom Anchors and other ReCom users.


 

Page generated in 0.30327 seconds with 14 queries