The site is loading…

https://docs.google.com/document/d/1SivPVqXB9kCiKycBCkvScJMFX84xeHjVY0WMqkMNjxs/edit

  1. /****************************************************************
  2.  *
  3.  * Purpose: Basic example of pipe. 
  4.  *          Read and write fixed length records across a pipe.
  5.  *          This is about a simple as they come...
  6.  *
  7.  ******************************************************************/
  8.  
  9. #include <sys/types.h>
  10. #include <unistd.h>			/* pipe.		*/
  11. #include <signal.h>
  12.  
  13. void Child  (int Handle);
  14. void Parent (int Handle);
  15.  
  16. void main()
  17. {
  18.  
  19.   pid_t		Pid;
  20.   int 		fd[2];
  21.  
  22.   pipe(fd);				/* Create two file descriptors 	*/
  23.  
  24.   Pid = fork();
  25.  
  26.   if ( Pid == 0)			/* Child			*/
  27.   {
  28.     close(fd[0]);
  29.     Child(fd[1]);
  30.     puts("Child end");
  31.   }
  32.   else					/* Parent.			*/
  33.   {
  34.     close(fd[1]);
  35.     Parent(fd[0]);
  36.     puts("Parent end");
  37.   }
  38. }
  39.  
  40. /****************************************************************
  41.  *
  42.  *      The Child sends data to the parent.
  43.  *
  44.  ****************************************************************/
  45.  
  46. void Child(int Handle)
  47. {
  48.   char Buff[]="Martin 1 abcdefghijklmnop ";
  49.  
  50.   write(Handle, Buff, strlen(Buff)+1);
  51.  
  52.   Buff[7] = '2';
  53.   write(Handle, Buff, strlen(Buff)+1);
  54.  
  55.   Buff[7] = '3';
  56.   write(Handle, Buff, strlen(Buff)+1);
  57.  
  58.   Buff[7] = '4';
  59.   write(Handle, Buff, strlen(Buff)+1);  
  60.  
  61.   close(Handle);
  62. }
  63.  
  64. /****************************************************************
  65.  *
  66.  *      Read the data sent by the child.
  67.  *
  68.  ****************************************************************/
  69.  
  70.  
  71. void Parent(int Handle)
  72. {
  73.  
  74.   char Buff[50];
  75.   /* ...	Read EXACTLY the number of bytes sent. 
  76.      ...	0 is returned when the pipe is closed by the child. */
  77.  
  78.   while (read(Handle,Buff, 27) > 0)
  79.   {
  80.     printf("%sn", Buff);
  81.   }
  82.  
  83. }

Continue reading

https://docs.google.com/document/d/1VSTohTGvtEUPWPGh7QY8tvdkKuWKLb6yoCQgDlKWzi0/edit

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define MAX_STR 128
  4.  
  5. typedef struct _ITALGEP{
  6.     int rekesz_id;
  7.     char italnev[MAX_STR];
  8.     int egysegar;
  9.     int darab;
  10.     char feltoltesi_datum[MAX_STR];
  11.     int eladott_db;
  12.     int forgalom;
  13.     int osszes_eladott_db;
  14.     int osszes_forgalom;
  15.     int ures;
  16.     int szin;
  17. } ITALGEP;
  18.  
  19. int main(){
  20.     ITALGEP gep;
  21.     printf ("rekesz_id: ");
  22.     scanf ("%d", &gep.rekesz_id);
  23.     FILE *fw = fopen("szoveg","wb");
  24.     while(gep.rekesz_id!=-1){
  25.    	 printf ("italnev: ");
  26.    	 scanf ("%s", gep.italnev);
  27.  
  28.    	 fwrite(&gep ,sizeof(gep),1,fw);
  29.  
  30.    	 printf ("rekesz_id: ");
  31.    	 scanf ("%d", &gep.rekesz_id);
  32.     }
  33.     fclose(fw);
  34.  
  35.     char adat[100];
  36.     FILE *fp = fopen("szoveg","rb");
  37.     if(fp!=NULL){
  38.    	 while(fgets(adat,100,fp)!=NULL){
  39.    		 printf("Az olvasott elem: %sn", adat);
  40.    	 }
  41.    	 fclose(fp);
  42.     } else {
  43.    	 printf("Hibas fajlnev!");
  44.     }
  45.  
  46.     return 0;
  47. }

Continue reading

https://docs.google.com/document/d/1R_rYGMRvzEaBQeMp0OtLd6v3L3-ajliMKf4YOBGnMcE/edit

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <time.h>
  5.  
  6. void kiir(int n, int *a);
  7.  
  8. int main(){
  9. 	int * input;
  10. //	int i;
  11. 	int i = 1;
  12. 	int ertek;
  13. 	int j;
  14. 	srand(time(NULL));
  15. 	int x = sizeof(int);
  16. 	int y = sizeof(int);
  17. 	input = (int *) malloc(x);
  18. 	for(j = 0; j < i; j++){
  19. 		printf("Kerem az erteket: ");
  20. 		scanf(" %d", &ertek);
  21. 		if(ertek>0){
  22. 			input = realloc(input, y);
  23. //			input[j] = rand() % 100;
  24. 			input[j] = ertek;
  25. 			y = y + x;
  26. 			i++;
  27. 		}
  28. 	}
  29. 	kiir(i, input);
  30. 	return 0;
  31. }
  32.  
  33. void kiir(int n, int *a){
  34. 	int i;
  35. 	for(i = 0; i < n; i++){
  36. 		printf("Az %d. elem: %dn", i , a[i]);
  37. 	}
  38. }
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <errno.h> // hibakezel괨ez
  4. #include <dirent.h>
  5. #include <sys/types.h>
  6. #include <string.h>
  7. #include <sys/stat.h>
  8.  
  9. void konyvtar(char form[], char di[]){
  10. 	DIR * D;
  11. 	struct dirent * direntp;
  12. 	struct stat my_status;
  13. 	char new_form[80];
  14. 	char new_form_s[80];
  15. 	char fname[80];
  16. 	strcpy(new_form, form);
  17. 	strcat(new_form, "t ");
  18. 	strcpy(new_form_s, form);
  19. 	strcat(new_form_s, "%sn");
  20.  
  21. 	chdir(di);
  22. 	D = opendir(".");
  23. 	if(!errno){
  24. 		// könyvtár nyitva, olvassuk
  25. 		while((direntp=readdir(D))!=NULL){
  26. 			strcpy(fname, direntp -> d_name);
  27. 			printf(new_form_s, fname);
  28. 			if((strcmp(fname, ".")!=0) && (strcmp(fname, "..")!=0)){
  29. 				stat(fname, &my_status);
  30. 				if(S_ISDIR(my_status.st_mode)){
  31. 					strcat(new_form, "t");
  32. 					konyvtar(new_form, fname);
  33. 				}
  34. 			}
  35. 		}
  36. 	}
  37. 	closedir(D);
  38. }
  39.  
  40. int main(){
  41. 	char D[80] = ".";
  42. 	printf("Az aktualis konyvtar tartalma: n");
  43. 	konyvtar(" ", D);
  44. 	return 0;
  45. }

Continue reading