Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Temas - x4cks

#1
Programación C/C++ / C ¿Windows?
6 Junio 2011, 02:17 AM
Hi brothers , vengo a decirles algo importante que quisa les dee mas ganas de aprender C

Nose porque hay muchos usuarios que se la pasan estudiando c y siempre se orientan para windows , ¿Por qué? , yo desde que empece c siempre he trabajado en gnu/linux nunca me gusto trabajarlo en windows.

Ejemplos de sockets en GNU/Linux y en Windows:
/**********************************************************************
* client.c --- Demonstrate a simple client.
* Tom Kelliher
*
* This program will connect to a simple iterative server and exchange
* messages.  The single command line argument is the server's hostname.
* The server is expected to be accepting connection requests from
* SERVER_PORT.
*
* The same message is sent three times over separate connections,
* demonstrating that different ephemeral ports are used for each
* connection.
**********************************************************************/


#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>


#define DATA "The sea is calm tonight, the tide is full . . ."
#define SERVER_PORT 5001
#define BUFFER_SIZE 1024


/* prototypes */
void die(const char *);
void pdie(const char *);


/**********************************************************************
* main
**********************************************************************/

int main(int argc, char *argv[]) {

  int sock;   /* fd for socket connection */
  struct sockaddr_in server;   /* Socket info. for server */
  struct sockaddr_in client;   /* Socket info. about us */
  int clientLen;   /* Length of client socket struct. */
  struct hostent *hp;   /* Return value from gethostbyname() */
  char buf[BUFFER_SIZE];   /* Received data buffer */
  int i;   /* loop counter */

  if (argc != 2)
     die("Usage: client hostname");

  /* Open 3 sockets and send same message each time. */

  for (i = 0; i < 3; ++i)
  {
     /* Open a socket --- not bound yet. */
     /* Internet TCP type. */
     if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
        pdie("Opening stream socket");
     
     /* Prepare to connect to server. */
     bzero((char *) &server, sizeof(server));
     server.sin_family = AF_INET;
     if ((hp = gethostbyname(argv[1])) == NULL) {
        sprintf(buf, "%s: unknown host\n", argv[1]);
        die(buf);
     }
     bcopy(hp->h_addr, &server.sin_addr, hp->h_length);
     server.sin_port = htons((u_short) SERVER_PORT);
     
     /* Try to connect */
     if (connect(sock, (struct sockaddr *) &server, sizeof(server)) < 0)
        pdie("Connecting stream socket");
     
     /* Determine what port client's using. */
     clientLen = sizeof(client);
     if (getsockname(sock, (struct sockaddr *) &client, &clientLen))
        pdie("Getting socket name");
     
     if (clientLen != sizeof(client))
        die("getsockname() overwrote name structure");
     
     printf("Client socket has port %hu\n", ntohs(client.sin_port));
     
     /* Write out message. */
     if (write(sock, DATA, sizeof(DATA)) < 0)
        pdie("Writing on stream socket");
     
     /* Prepare our buffer for a read and then read. */
     bzero(buf, sizeof(buf));
     if (read(sock, buf, BUFFER_SIZE) < 0)
        pdie("Reading stream message");
     
     printf("C: %s\n", buf);
     
     /* Close this connection. */
     close(sock);
  }

  exit(0);

}


/**********************************************************************
* pdie --- Call perror() to figure out what's going on and die.
**********************************************************************/

void pdie(const char *mesg) {

  perror(mesg);
  exit(1);
}


/**********************************************************************
* die --- Print a message and die.
**********************************************************************/

void die(const char *mesg) {

  fputs(mesg, stderr);
  fputc('\n', stderr);
  exit(1);
}




http://msdn.microsoft.com/en-us/library/ms741394%28v=vs.85%29.aspx no encontre otro.

Windows?
Por que aprender c orientado a windows?
que veneficio hay?
Linux/unix!
Tiene muchos veneficios , me gusta mas su sintaxis , aprender c usando linux/unix es lo mejor , imaginate que no sepas para que sirve tal libreria o tal funcion , primero no sabes usar esa libreria pero luego aprendes 100 librerias mas , ¿como?
Use the ManPage wiki
Man pages (short for manual pages) are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is man. Each page is a self-contained document.
Para usar simplemente lo haces asi:
man stdio.h ¿Por que digo k aprendes a usar otras librerias o funciones?
al final del man tienen unas referencias , yo todo lo que se de C/C++ lo aprendi usando man y practicando mucho , y algunos libros pero mas el man.


NAME

   stdio.h - include definitions for standard buffered input/output

SYNOPSIS

   #include <stdio.h>

DESCRIPTION

   The <stdio.h> header includes the following kinds of definitions:

       Constants subsection of stdio.h(4)
       Data Types subsection of stdio.h(4)
       External Variables subsection of stdio.h(4)
       Function Prototypes subsection of stdio.h(4)

   Inclusion of the <stdio.h> header may make visible all symbols from the <stddef.h> header.
   Constants

   The following macro names are defined as positive integral constant expressions.

   BUFSIZ
       Size of <stdio.h> buffers.
   FILENAME_MAX
       Maximum size in bytes of the longest file name string that the system guarantees can be opened.
   FOPEN_MAX
       Number of streams that the system guarantees can be open simultaneously. The value will be at least eight.
   _IOFBF
       Input and output fully buffered.
   _IOLBF
       Input and output line buffered.
   _IONBF
       Input and output unbuffered.
   L_ctermid
       Maximum size of character array to hold ctermid() output.
   L_tmpnam
       Maximum size of character array to hold tmpnam() output.
   SEEK_CUR
       Seek relative to current position.
   SEEK_END
       Seek relative to end-of-file.
   SEEK_SET
       Seek relative to start-of-file.
   TMP_MAX
       Minimum number of unique file names generated by tmpnam(). Maximum number of times an application can call tmpnam() reliably. The value of TMP_MAX will be at least 10,000.

   The following defined constant is scheduled to be withdrawn from a future version of the Single UNIX Specification:

   L_cuserid
       Maximum size of character array to hold cuserid() output.

   Macros

   The following macro name is defined as a negative integral constant expression:

   EOF
       End-of-file return value.

   The following macro name is defined as a null pointer constant:

   NULL
       Null pointer.

   The following macro name is defined as a string constant:

   P_tmpdir
       Default directory prefix for tempnam().

   The following macro names are defined as expressions of type pointer to FILE:

   stderr
       Standard error output stream.
   stdin
       Standard input stream.
   stdout
       Standard output stream.

   Data Types

   The following data types are defined through typedef:

   FILE
       A structure containing information about a file.
   fpos_t
       Type containing all information needed to specify uniquely every position within a file.
   size_t
       Unsigned integral type of the result of the sizeof operator.
   va_list
       Defined for variables used to traverse a variable argument list, as described in the stdarg.h(4) reference page.

   External Variables

   The following are defined as external variables. These external variables are scheduled to be withdrawn from a future version of the Single UNIX Specification.

   extern char *optarg
   extern int opterr
   extern int optind
   extern int optopt

   These variables are also defined in the <unistd.h> header.
   Function Prototypes

   The following are declared as functions and may also be defined as macros. An application programmer can use an #undef statement to remove the macro definition and ensure that the program uses the actual function.

   void clearerr(FILE *stream);

   char *ctermid(char *s);

   int fclose(FILE *stream);

   FILE *fdopen(int fildes, const char * mode);

   int feof(FILE *stream);

   int ferror(FILE *stream);

   int fflush(FILE *stream);

   int fgetc(FILE *stream);

   int fgetpos(FILE *stream, fpos_t *pos);

   char *fgets(char *s, int n, FILE *stream);

   int fileno(FILE *stream);

   FILE *fopen(const char *filename, const char *mode);

   int fprintf(FILE *stream, const char *format, ...);

   int fputc(int c, FILE *stream);

   int fputs(const char *s, FILE *stream);

   size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
           

   FILE *freopen(const char *filename, const char *mode,
           FILE *stream);

   int fscanf(FILE *stream, const char *format, ...);

   int fseek(FILE *stream, long int offset, int whence);

   int fsetpos(FILE *stream, const fpos_t *pos);

   long int ftell(FILE *stream);

   size_t fwrite(const void *ptr, size_t size, size_t nitems,
           FILE *stream);

   int getc(FILE *stream);

   int getchar(void);

   char *gets(char *s);

   int getw(FILE *stream);

   int pclose(FILE *stream);

   void perror(const char *s);

   FILE *popen(const char *command, const char *mode);

   int printf(const char *format, ...);

   int putc(int c, FILE *stream);

   int putchar(int c);

   int puts(const char *s);

   int putw(int w, FILE *stream);

   int remove(const char *path);

   int rename(const char *old, const char *new);

   void rewind(FILE *stream);

   int scanf(const char *format, ...);

   void setbuf(FILE *stream, char *buf);

   int setvbuf(FILE *stream, char *buf, int type, size_t size);

   int sprintf(char *s, const char *format, ...);

   int sscanf(const char *s, const char *format, int ...);

   char *tempnam(const char *dir, const char *pfx);

   FILE *tmpfile(void);

   char *tmpnam(char *s);

   int ungetc(int c, FILE *stream);

   int vfprintf(FILE *stream, const char *format, va_list ap);

   int vprintf(const char *format, va_list ap);

   int vsprintf(char *s, const char *format, va_list ap);

   The following declared functions are scheduled to be withdrawn from a future version of the Single UNIX Specification:

   char *cuserid(char *s);

   int getopt(int argc, const char *argv[], const char *optstring);

SEE ALSO

   clearerr(3), ctermid(3), cuserid(3), fclose(3), fdopen(3), feof(3), ferror(3), fflush(3), fgetc(3), fgetpos(3), fgets(3), fileno(3), fopen(3), fputc(3), fputs(3), fread(3), freopen(3), fseek(3), fsetpos(3), ftell(3), fwrite(3), getc(3), getchar(3), getopt(3), gets(3), getw(3), getwchar(3), pclose(3), perror(3), popen(3), printf(3), putc(3), putchar(3), puts(3), putw(3), putwchar(3), remove(3), rename(2), rewind(3), scanf(3), setbuf(3), setvbuf(3), sscanf(3), system(3), tempnam(3), tmpfile(3), tmpnam(3), ungetc(3), vprintf(3), stdarg.h(4), stddef.h(4), systypes.h(4), stdin(5), xshstdiostr(5)


Lo ven  , todas esas referencias?




Espero que reflexionen y opinen que es mejor trabajar en unix/linux o windows?

Linux rlZ!

PD: Yo trabajo en windows en c a nivel basico porque todo es casi igual pero despues me voy mas para el lado de gnu/linux ,para todos aquellos que quieran aprender c les recomiendo usar el kernel gnu/linux. ¿APIS WINDOWS ajajaja? - nunca las estudie ni siquiera me interesan.
GTK obvio que si

Corriganme si es que me equivoco.
Saludos