简体   繁体   中英

warning: passing arg 1 of `atoi' makes pointer from integer without a cast

I am learning C language one year and it is my first time that I got that warning. This is my code:

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


 int socket_creation(FILE* fp){
        int s;
        s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
        if (s == INVALID_SOCKET){
                printf("Error occurred while creating socket: %d\n", WSAGetLastError());
                fprintf(fp, "Error occurred while creating socket: %d\n", WSAGetLastError());
        }
        else{
                printf("Socket creation was successful.\n");
                fprintf(fp, "Socket creation was successful.\n");
        }
        return s;
}


void connect_to_server(int s, struct sockaddr_in ClientService, FILE* fp){
        int cResult;
        cResult = connect(s, (struct sockaddr*) &ClientService, sizeof(ClientService));
        if (cResult == SOCKET_ERROR){
                printf("connection to the server has been failed: %d\n", WSAGetLastError());
                fprintf(fp, "connection to the server has been failed: %d\n", WSAGetLastError());
                cResult = closesocket(s);
                if (cResult == SOCKET_ERROR){
                        printf("error occurred while trying to close socket. \n");
                        fprintf(fp, "error occurred while trying to close socket. \n");
                }
                WSACleanup();
        }
        else{
                printf("Connection to serevr has been made successfully. \n");
                fprintf(fp, "Connection to serevr has been made successfully. \n");
        }
}

int send_to_serv(char buffer[], int s){
        int sendto;
        sendto = send(s, buffer, 1024, 0);
        if (sendto == -1)
                printf("\nError: couldn't send the Code.\n", buffer);
        else printf("\nCode: <%s> SENT.\n", buffer);
        return sendto;
}

int recv_from_serv(int s, int* numberLines, FILE *fp){

        int recvfrom;
        char buffer[1024] = "";

        recvfrom = recv(s, buffer, 1024, 0);
        if (recvfrom == -1)
        printf("\nError: couldn't receive Code. !\n");
        else printf("\nRespond: <%s>, RECEIVED. \n", buffer);
        fprintf(fp, "\n");
        fprintf(fp, buffer);

        *numberLines = atoi(buffer + 3);
        return recvfrom;
}

int main() {

        WSADATA info;
        int error, s;
        int sResults, sendError, recvError,convert2;
        char buffer[1024] = "";
        char recvbuf[1024] = "";
        int numberLines, i, temp, convert;
        char converted_num[1024] = "";
        struct sockaddr_in ClientService;
        FILE *fp = fopen("stored_data.txt", "w");
        char **lines_array = NULL;
        error = WSAStartup(MAKEWORD(2, 0), &info);

        if (error != 0){
                printf("WSAstartup failed with error: %d\n", error);
                exit(1);
        }

        s = socket_creation(fp);

        ClientService.sin_family = AF_INET;
        ClientService.sin_addr.s_addr = inet_addr("54.209.143.42");
        ClientService.sin_port = htons(6714);

        connect_to_server(s, ClientService, fp);

        strcpy(buffer, "100");
        sendError = send_to_serv(buffer, s);
        recvError = recv_from_serv(s, &numberLines, fp);

        strcpy(buffer, "400");
        sendError = send_to_serv(buffer, s);
        recvError = recv_from_serv(s, &numberLines, fp);
        printf("\nNumber of Lines are: %d\n", numberLines);

        lines_array = malloc(sizeof(char*)*numberLines);
        temp = numberLines;

        for (i = 0; i < temp; i++){
                convert = 5000001 + i;
                _itoa(convert, converted_num, 10);
                sendError = send_to_serv(converted_num, s);
                convert2=atoi(convert);
                convert=convert%10000;
                if(convert2==0) {
                        for(i=0; i<=1024; i++) {
                                buffer[i]=0;
                        }
                        lines_array= (convert);
                        recv_from_serv(s, &numberLines, fp);
                }
                else{
                        for(i=0; i<=1024; i++) {
                                buffer[i]=0;
                                fprintf(fp, "\n");
                                fprintf(fp, buffer);
                        }
                }
        }

        close(fp);
        system("PAUSE");
        return 0;
 }

Output: finalproject1.c:110: warning: passing arg 1 of `atoi' makes pointer from integer without a cast

It's mean that I have problem with row number 110:

convert2=atoi(convert);

You are calling atoi on convert, which is an int.

Earlier you appear to have put the relevant values into converted_num using _itoa, so you probably want to pass converted_num to atoi rather than passing convert to it:

convert2=atoi(converted_num);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM