We are trying to send several emails via C language on a centos 6.2 platform. Below are the codes.
I added and left char *filename = ""; the I get error as sh: TEST: No such file or directory sh: TEST: No such file or directory sh: TEST: No such file or directory. If I add a message to it give me another error warning: incompatible implicit declaration of built-in function âsprintfâ
How to solve this issue?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define cknull(x) if((x)==NULL) {perror(""); exit(EXIT_FAILURE);}
#define cknltz(x) if((x)<0) {perror(""); exit(EXIT_FAILURE);}
#define LIST_LEN 4


void main()                                          
{                                                                       
    char tmp[256]={0x0};                                                
    char fpBuffer[512]={0x0};                                           
    char email_list[LIST_LEN][256]={  {"****@gmail.com"},             
                               {"****@gmail.com"},             
                               {"***@gmail.com"},         
                               {0x0}};                                  
    int i=0;                                                            
    char *filename = "";                                                                    
    for(i=0;*email_list[i]>0x0;i++)                                
    {                                                                   
        cknull(strcpy(tmp, email_list[i]));                             
        cknltz(sprintf (fpBuffer,                                       
            "/usr/bin/mailx -s '%s %s' %s < %s",                        
            "Please Review:",                                           
            filename,                                                   
            tmp,                                                        
            filename));                                                 
        if(system (fpBuffer)==(-1))                                     
        {                                                               
            perror("email failure");                                    
            exit(EXIT_FAILURE);                                         
        }                                                               
    }                                                                   
}

I haven't use centos yet, but it seems that it is not the problem. I think that the problem is here: for(i=0;*email_list[i]>0x0;i++). Why are you calling with '*' if you are using '[]'? Try changing that part like this: for(i=0;email_list[i]>0x0;i++).

line 22: cknull macro is useless waste of cpu time becaye strcpy() will never return NULL unless a NULL pointer is sent to strcpy() as the destination string. If that happens strcpy() will just crash the whole program because it will attempt to write to memory address 0.

The value of filename is never set to anything but "".

Try changing that part like this: for(i=0;email_list[i]>0x0;i++).

That won't work. The original code is ok because it's checking for email_list[i][0], and that is the same thing as *email_list[i]

Actually, it could work because email_list[i][0] is a character and not a pointer as email_list[i]. The character could be '\0' or 0x0, but if the pointer is 0x0 then the character will be unreadable and the string will be the last.

email_list[i] is not a pointer so it can't be tested for NULL (0x0 == NULL). Line 17 doesn't set a pointer to NULL, but instead sets the first byte of the last element to '\0'. There are still 256 bytes in that array. You would have been correct had it been declared like this char* email_list[LIST_LEN]

So what is the recommended changes are required in order for it to run. I want the char *filename = ""; to have the email message how that is possible?

what is the email message??? We can't tell you wnat it is because we didn't write the program. We have no clue what the message is supposed to be. If the message is "Hello World" then char *filename = "Hello World", but that isn't reasonable. I would assume from the name of the variable that filename should point to the name of a file, such as char* filename = "c:/SomeFile.txt"

You should be asking your questions on Centos's forums at this link

I have tried this char *filename = "Hello World"; then I error message as

sendEmail.c: In function âmainâ:
sendEmail.c:30: warning: incompatible implicit declaration of built-in function âsprintfâ

The error is referring to

cknltz(sprintf (fpBuffer,                                       
        "/usr/bin/mailx -s '%s %s' %s < %s",                        
        "Please Review:",                                           
        filename,                                                   
        tmp,                                                        
        filename));     

delete the macro cknltz from that line.

Remove but still the same error is showing up.

what compiler are you using? I compiled the code in your first post with Microsoft's Visual Studio 2012 and did not get any errors. Is that the entire code in sendEmail.c?

I am compiling using gcc in centos gcc -o sc sendEmail.c .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.