Informatika2-2012/Eloadas07
A MathWikiből
A lap korábbi változatát látod, amilyen Ador (vitalap | szerkesztései) 2012. március 20., 11:27-kor történt szerkesztése után volt.
Tartalomjegyzék |
Egyéb hasznosságok C programozáshoz
Konstansok
A program paraméterezése
A main() paraméterezése:
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { while(argc--) printf("%s\n", *argv++); exit(EXIT_SUCCESS); }
http://www.cprogramming.com/tutorial/c/lesson14.html
#include <stdio.h> int main ( int argc, char *argv[] ) { /* argc should be 2 for correct execution */ if (argc != 2) { /* We print argv[0] assuming it is the program name */ printf( "usage: %s filename", argv[0] ); } else { // We assume argv[1] is a filename to open FILE *file = fopen( argv[1], "r" ); /* fopen returns 0, the NULL pointer, on failure */ if (file == 0) { printf( "Could not open file\n" ); } else { int x; /* read one character at a time from file, stopping at EOF, which indicates the end of the file. Note that the idiom of "assign to a variable, check the value" used below works because the assignment statement evaluates to the value assigned. */ while ((x = fgetc(file)) != EOF ) { printf( "%c", x ); } fclose( file ); } } }
C függvénykönyvtárak
Matematikai függvények
math.h http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.7.html
Standard definíciók
stddef.h http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.11.html
Standard I/O
stdio.h http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.12.html
Standard dolgok
stdlib.h http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.13.html
Macros:
NULL RAND_MAX
Variables:
typedef size_t typedef wchar_t
Functions: abs(); labs(); atof(); atoi(); atol(); malloc(); calloc(); free(); qsort(); rand(); srand();
Stringből számmá konvertáló függvények
atoi(), atof(),
Random számok generálása
rand(); srand();
Stringek
string.h http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.14.html
Ellenőrző kérdések
Amit a zh-ra tudni kell:
- makrók definiálása
- stringek kezelése (előző előadás végén is volt)
- main paraméterezése hogy néz ki
- file olvasás, írás