Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    [C] Problemi di Ritorno con i Puntatori

    Ho un piccolo problema con i puntatori, stringhe e malloc...
    Io nella funzione make_request() dichiaro un puntatore a char che poi sara' passato alla funzione make_request_http10()...
    Questa con un malloc allochera' la memoria per la stringa e la inserira' nella "stringa" request...

    Il Problema e' che se stampo request all'interno della funzione dove c'e' il malloc la stringa si vede correttamente... Mentre nell'altra non si vede piu'...
    Come mai ???

    codice:
    char *make_request (const char *dirANDfile, const char *hostname, 
    					const char *useragent, short int protocol) 
    {
    	char *request;
    	
    	switch (protocol) {
    		case HTTP_10:	make_request_http10 (request, dirANDfile, useragent);
    						printf ("[%s]", request);
    						return (request);
    		case HTTP_11: 	make_request_http11 (request, dirANDfile, hostname, useragent);
    						printf ("[%s]", request);
    						return (request);
    	}
    	
    	return (NULL);
    }
    codice:
    char *make_request_http10 (char *request, const char *dirANDfile, const char *useragent) {
    	unsigned int dimreq;
    	
    	dimreq = strlen("GET ") + strlen(dirANDfile) + strlen(" HTTP/1.0\r\n");
    	dimreq += strlen("User-Agent:") + strlen(useragent) + strlen("\r\n\r\n");
    	
    	if ((request = (char *) malloc ((1+dimreq)*sizeof(char))) == NULL) {
    		return (NULL);
    	}
    	
    	/* GET /page HTTP/1.0\r\n\r\n */	
    	strcpy (request, "GET ");
    	strcat (request, dirANDfile);
    	strcat (request, " HTTP/1.0\r\n");
    	strcat (request, "User-Agent: ");
    	strcat (request, useragent);
    	strcat (request, "\r\n\r\n");
    	request[dimreq] = '\0';
    	
    	return (request);
    }

    Grazie
    #include <stdio.h>
    int main() { char m[18+1] = "_TeYS_We2^[TWda [f";
    int i = (((3*7))-21); for (; m[i]; i++)
    (i<27) ? m[i]+=(((13)*3)-25) : m[i] -= (7+(i)*(-1));
    puts(m); getchar(); return 0; };

  2. #2
    Ieri ero davvero fuso...
    codice:
    char **make_request_http10 (char **request, const char *dirANDfile, const char *useragent) {
    	unsigned int dimreq;
    	
    	dimreq = strlen("GET ") + strlen(dirANDfile) + strlen(" HTTP/1.0\r\n");
    	dimreq += strlen("User-Agent:") + strlen(useragent) + strlen("\r\n\r\n");
    	
    	if ((*request = (char *) malloc ((1+dimreq)*sizeof(char))) == NULL) {
    		return (NULL);
    	}
    	
    	/* GET /page HTTP/1.0\r\n\r\n */	
    	strcpy (*request, "GET ");
    	strcat (*request, dirANDfile);
    	strcat (*request, " HTTP/1.0\r\n");
    	strcat (*request, "User-Agent: ");
    	strcat (*request, useragent);
    	strcat (*request, "\r\n\r\n");
    	*request[dimreq] = '\0';
    	
    	return (request);
    }
    #include <stdio.h>
    int main() { char m[18+1] = "_TeYS_We2^[TWda [f";
    int i = (((3*7))-21); for (; m[i]; i++)
    (i<27) ? m[i]+=(((13)*3)-25) : m[i] -= (7+(i)*(-1));
    puts(m); getchar(); return 0; };

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.