6 C różne

Przydatne zestawienie


The 15 standard headers in C89 are:
<assert.h>  <limits.h>  <signal.h>  <stdlib.h>
<ctype.h>   <locale.h>  <stdarg.h>  <string.h>
<errno.h>   <math.h>    <stddef.h>  <time.h>
<float.h>   <setjmp.h>  <stdio.h>

The 6 extra headers in C99 are:
<complex.h>  <inttypes.h>  <stdint.h>  <tgmath.h>
<fenv.h>     <stdbool.h>
The 5 extra headers in C2011 (for a total of 29) are:
<stdalign.h>  <stdatomic.h>  <stdnoreturn.h>  <threads.h>  <uchar.h>

podstawowe:
#include <stdio.h>        (c wej/wyj)
#include <string.h)  ( strcpy()  )
#include <stdlib.h>  ( malloc  )

#include <iostream>     (c++)

int main(int argc, char **argv) {
    int i;         /* zmienna całkowita (typu int) 'i' */
    int *p;        /* wskaźnik 'p' wskazujący na zmienną całkowitą */
    int a[0];       /* tablica 'a' liczb całkowitych typu int */
    int f();       /* funkcja 'f' zwracająca liczbę całkowitą typu int */
    int **pp;      /* wskaźnik 'pp' wskazujący na wskaźnik wskazujący na liczbę całkowitą typu int */
    int (*pa)[0];   /* wskaźnik 'pa' wskazujący na tablicę liczb całkowitych typu int */
    int (*pf)();   /* wskaźnik 'pf" wskazujący na funkcję zwracającą liczbę całkowitą typu int */
    int *ap[0];     /* tablica 'ap' wskaźników na liczby całkowite typu int */
    int *fp();     /* funkcja 'fp', która zwraca wskaźnik na zmienną typu int */
    int ***ppp;    /* wskaźnik 'ppp' wskazujący na wskaźnik wskazujący na wskaźnik wskazujący na liczbę  typu int */
    int (**ppa)[0]; /* wskaźnik 'ppa' wskazujący na wskaźnik wskazujący na tablicę liczb całkowitych typu int */
    int (**ppf)(); /* wskaźnik 'ppf' wskazujący na wskaźnik funkcji zwracającej dane typu int */
    int *(*pap)[0]; /* wskaźnik 'pap' wskazujący na tablicę wskaźników na typ int */
    int *(*pfp)(); /* wskaźnik 'pfp' na funkcję zwracającą wskaźnik na typ int*/
    int **app[0];   /* tablica wskaźników 'app' wskazujących na wskaźniki wskazujące na typ int */
    int (*apa[0])[0];/* tablica wskaźników 'apa' wskazujących na tablicę liczb całkowitych typu int */
    int (*apf[0])();/* tablica wskaźników 'apf' na funkcje, które zwracają typ int */
    int **fpp();   /* funkcja 'fpp', która zwraca wskaźnik na wskaźnik, który wskazuje typ int */
    int (*fpa())[0];/* funkcja 'fpa', która zwraca wskaźnik na tablicę liczb typu int */
    int (*fpf())();/* funkcja 'fpf', która zwraca wskaźnik na funkcję, która zwraca dane typu int */

    return 0;
}


Przykład rozdzielenie forka i podwójnego pipa do przesyłu danych w obie strony
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

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

 int fd[2];
 int ff[2];
 int nbytes;
 pid_t childpid;
 char string2[] = "pier*** sie!\n";
 char string[] = "dzien dobry\n";
 char readbuffer[80];
 char readbuffer2[80];

 pipe(fd);
 pipe(ff);
/*
 if((childpid = fork()) == -1) {
  perror("fork");
  exit(1);
 }
*/

childpid=fork();

/*printf("wyswietlam id childid %d\n",childpid);*/

 if(childpid != 0) {
 printf("id ktory otrzymal rodzic (czyli realny dziecka) %d\n",childpid);
  close(fd[0]);
  write(fd[1], string, (strlen(string)+1));

  close(ff[1]);
  read(ff[0],readbuffer2,sizeof(readbuffer2));
  printf("Rodzic otrzymal komunikat: %s",readbuffer2);
  
  exit(0);
 } else {
  close(fd[1]);
  nbytes = read(fd[0],
         readbuffer,
         sizeof(readbuffer));
  printf("Dziecko otrzymalo komunikat: %s", readbuffer);
   
  close(ff[0]);
  write(ff[1], string2, (strlen(string2)+1));
  exit(0);


 }
 return (0);
}

The Standard C library headers

<assert.h>Conditionally compiled macro that compares its argument to zero
<complex.h> (since C99)Complex number arithmetic
<ctype.h>Functions to determine the type contained in character data
<errno.h>Macros reporting error conditions
<fenv.h> (since C99)Floating-point environment
<float.h>Limits of float types
<inttypes.h> (since C99)Format conversion of integer types
<iso646.h> (since C95)Alternative operator spellings
<limits.h>Sizes of basic types
<locale.h>Localization utilities
<math.h>Common mathematics functions
<setjmp.h>Nonlocal jumps
<signal.h>Signal handling
<stdalign.h> (since C11)alignas and alignof convenience macros
<stdarg.h>Variable arguments
<stdatomic.h> (since C11)Atomic types
<stdbool.h> (since C99)Boolean type
<stddef.h>Common macro definitions
<stdint.h> (since C99)Fixed-width integer types
<stdio.h>Input/output
<stdlib.h>General utilities: memory managementprogram utilitiesstring conversionsrandom numbers
<stdnoreturn.h> (since C11)noreturn convenience macros
<string.h>String handling
<tgmath.h> (since C99)Type-generic math (macros wrapping math.h and complex.h)
<threads.h> (since C11)Thread library
<time.h>Time/date utilities
<uchar.h> (since C11)UTF-16 and UTF-32 character utilities
<wchar.h> (since C95)Extended multibyte and wide character utilities
<wctype.h> (since C95)Functions to determine the type contained in wide character data