0

can i return a value using CHAR DATA TYPE? NOT INT?
ex.int data;
int value(ex.data)
return data;
how about this
ex.char name;
int(ex.name)
return name;
possible or not?

2
Contributors
6
Replies
7
Views
4 Years
Discussion Span
Last Post by ilovephil
0

Yes

char GetChar()
{
   return 'a';
}

or

char GetChar(int iValue)
{
   return (char) iValue; //there can be side-effects if the value is outside of the range.
}

Edited by thines01: n/a

0

how about in link list may i use that?i need to store strings. my problem is i cannot solve my problem in strings can u help me? =))

0

What do you mean?
Yes, you can store a char in a linked list.

What are you trying to do?
I should not guess at potential solutions when I don't know the actual problem.

Is this the same question?

Edited by thines01: added link

0

HERE HOW TO store strings in this list
>_<
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define p printf
#define s scanf
struct node
{
char nbook;
struct node *next;
};
typedef struct node *nodepointer;
void addbook(nodepointer &head,char book[50])
{
nodepointer newnode;
newnode=(nodepointer)malloc(sizeof(struct node));
newnode->nbook=book[50];
newnode->next=head;
head=newnode;
}
void display(nodepointer head)
{
if(head==NULL)
{
p("\nNothing to display");
}
else if(head!=NULL)
{
while(head->next!=NULL)
{
p("\n%s",head->nbook);
head=head->next;
}
p("\n%s",head->nbook);
}
}
main()
{
nodepointer head=NULL;
int choice;
char book[50];
do
{
p("\n[1]Add book");
p("\n[2]Display book");
p("\nKey choice: ");
s("%i",&choice);
switch(choice)
{
case 1:
p("\nEnter title of book");
s("\n%s",&book);
addbook(head,book);
break;
case 2:
display(head);
break;
}
}while(choice!=4);
system("pause");
}

0

Please don't post the same question multiple times.
Please use code tags to make code easier to read.
Please search the site for example of common homework problems and solutions like linked lists.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.