Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.20/5 (2 votes)
See more:
C++
struct node
{
char data;
struct node *link;
}*last=NULL,*tmp;

void insert();
void display();

void main()
{
int len1,len2;
int i=0,j=0,k,l;
int count=0;
char name1[15];
char name2[15];

printf("Enter the Name1: ");
scanf("%s",name1);
printf("Enter the Name2: ");
scanf("%s",name2);
len1= strlen(name1);
len2= strlen(name2);

while(name1[i]!='\0')
{
for(j=0;name2[j]!='\0';j++)
     {
    if(name1[i]==name2[j])
      {
        count = count + 2;
        break;
      }
      }
   i++;
}
count = ((len1+len2)-count);
printf("%d\n",count);
printf("%s\n%s\n",name1,name2);

//Just Enter the flames string
printf("Enter the flames text character by character ");

printf("\n1");
insert();
printf("\n2");
insert();
printf("\n3");
insert();
printf("\n4");
insert();
printf("\n5");
insert();
printf("\n6");
insert();
display();
}

void insert()
{
char fl;
tmp = (struct ndode *) malloc(sizeof (struct node));
scanf("%c",&fl);
printf("%c",fl);
tmp->data = fl;

if(last == NULL)
{
printf("Hello this first time");

last = tmp;
tmp->link = last;
}
else
{
tmp->link = last->link;
last->link = tmp;
last = tmp;
}
}

void display()
{
struct node *t;
t = last->link;
while(t != last)
{
printf("%c\n",t->data);
t = t->link;
}
printf("%c\n",t->data);
}
Posted
Updated 22-Feb-14 19:16pm
v4
Comments
OriginalGriff 18-Feb-14 5:03am    
First thing you need to do: give us actual information - and that includes your code.
Make it easy for us to read: remove the redundant commented out code, and indent the rest so it is simple to see what is going on when you aren't familiar with it.

Then, remember that we can;t see you screen, access your HDD, or read your mind, and we have no idea what a "C program for flames" actually is: so we don't know what your code is supposed to do. And we also don't know what it does do, so it's difficult to work out what might be wrong.

So edit your question, sort out the stuff above, and explain what it does that you didn't expect, or doesn't do that you did - and how you got it to do it. It would also help if you told us how you know it's wrong!

Use the "Improve question" widget to edit your question and provide better information.

1 solution

1. use fscanf, not scanf. If someone types a name longer than 15 characters, your program may crash.
2. call fflush(stdin) after each scanf/fscanf. This will consume the carriage return allowing the next character to be read.
3. when declaring character arrays, it's best to initialize them like so:
char name[15] = {0};

... or ...
memset(name, 0, sizeof name);

Makes debugging easier since you can distinguish characters actually read from characters set to nul.
 
Share this answer
 

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

  Print Answers RSS


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