简体   繁体   English

警告:传递 `atoi' 的 arg 1 使指针从整数而不进行强制转换

[英]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.我正在学习 C 语言一年,这是我第一次收到警告。 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输出: finalproject1.c:110:警告:传递 `atoi' 的 arg 1 使指针从整数而不进行强制转换

It's mean that I have problem with row number 110:这意味着我的第 110 行有问题:

convert2=atoi(convert);

You are calling atoi on convert, which is an int.您在转换时调用 atoi,这是一个 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:早些时候,您似乎已经使用 _itoa 将相关值放入了converted_num,因此您可能希望将converted_num 传递给atoi,而不是将convert 传递给它:

convert2=atoi(converted_num);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 &#39;atoi&#39; 的传递参数 1 使指针来自整数而不在 C 中进行强制转换 - passing argument 1 of 'atoi' makes pointer from integer without a cast in C C strcat-警告:传递&#39;strcat&#39;的arg 2会使指针从整数转换而无需强制转换 - C strcat - warning: passing arg 2 of `strcat' makes pointer from integer without a cast 传递&#39;memset&#39;的arg 2可以从指针进行整数转换而无需强制转换 - Passing arg 2 of `memset' makes integer from pointer without a cast 警告:传递&#39;memcpy&#39;的参数1会使指针从整数开始而无需强制转换 - warning: passing argument 1 of ‘memcpy’ makes pointer from integer without a cast 警告传递&#39;finder&#39;的参数2使指针从整数开始而无需强制转换 - Warning passing argument 2 of 'finder' makes pointer from integer without a cast 警告:传递&#39;fopen&#39;的参数2会使指针从整数开始而无需强制转换 - warning: passing argument 2 of ‘fopen’ makes pointer from integer without a cast 警告:传递&#39;calcFx&#39;的参数2将使指针产生整数而不进行强制转换 - warning: passing argument 2 of 'calcFx' makes integer from pointer without a cast 警告:传递&#39;strcpy&#39;的参数1会使指针从整数开始而不进行强制转换 - warning: passing argument 1 of ‘strcpy’ makes pointer from integer without a cast 传递参数 1 从指针生成整数而没有强制转换警告 - Passing Argument 1 makes integer from pointer without a cast warning 传递参数 1 从指针生成 integer 而没有对 putchar 的强制转换警告 - Passing Argument 1 makes integer from pointer without a cast warning for putchar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM