Hi ,
I am writing a code for writing a whole string to file,but it is running in infinte loop ??
Means the final string is written infinte times.
The code is:
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct file
{
char send_mail[20];
char smtp[20];
char to[50];
char from[50];
};
int main()
{
file *ptr;
FILE *fptr;
ptr = (struct file *)malloc(sizeof(file));
strcpy(ptr->send_mail,"send_smtp_mail ");
strcpy(ptr->smtp,"127.0.0.1 ");
strcpy(ptr->to,"[email protected] ");
strcpy(ptr->from,"[email protected] ");
strcat(ptr->send_mail,ptr->smtp);
strcat(ptr->send_mail,ptr->to);
strcat(ptr->send_mail,ptr->from);
strcat(ptr->send_mail,"\n");
printf("\n%s\n",ptr->send_mail);
fptr = fopen("/home/bargi/malloc/tmp.txt","w");
if (fptr == NULL)
printf("NULL");
while(ptr->send_mail != "\n")
{
fputs(ptr->send_mail,fptr);
}
fclose(fptr);
}
Can anyone explain why the loop is running infinte..
Thanks