Thread: Problem in writing string to File

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    113

    Problem in writing string to File

    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
    Last edited by Bargi; 02-18-2009 at 11:46 AM. Reason: more expalination

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. string pattern search problem
    By goron350 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 08:50 AM
  4. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM