daily pastebin goal
71%
SHARE
TWEET

Untitled

a guest May 27th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include "wchar.h"
  3. #include <stdlib.h>
  4.  
  5. void ostdin ();
  6. int ofile (char *filename);
  7. wchar_t * getuchar();
  8.  
  9. int
  10. main (int argc, char *argv[])
  11. {
  12.  
  13.   if (argc == 1)
  14.     {
  15.       printf ("Nie podano żadnych argumentów\n");
  16.       ostdin ();
  17.     }
  18.   else if (argv[1][0] == '-')
  19.     {
  20.       if (argv[1][1] == '\0')
  21.     {
  22.       printf ("Jako argument podano '%s'\n", argv[1]);
  23.       ostdin ();
  24.     }
  25.       else
  26.     printf ("Błąd!\nPodano zły argument\n");
  27.     }
  28.   else
  29.     {
  30.       if (ofile (argv[1]) == -1)
  31.     printf ("Błąd!\nNie udało się otworzyć pliku \"%s\"\n", argv[1]);
  32.     }
  33.   return 0;
  34. }
  35.  
  36. void
  37. ostdin ()
  38. {
  39.   wchar_t *test;
  40.   printf ("Program odczytuje standardowe wejscie (stdin)\n");
  41.   printf ("*******************************************\n");
  42.   while (test=getuchar()){
  43.     printf("Znak = ");
  44.     fputws(test,stdout);
  45.     printf("\n");
  46.   }
  47. }
  48.  
  49. int
  50. ofile (char *filename)
  51. {
  52.   int c;
  53.   FILE *input = fopen (filename, "r");
  54.  
  55.   if (input == NULL)
  56.     return -1;
  57.  
  58.   printf ("Program odczytał plik o nazwie \"%s\"\n", filename);
  59.   printf ("*******************************************\n");
  60.   while ((c = fgetc (input)) != EOF){
  61.     putchar (c);
  62.     printf("\n");
  63.   }
  64.   printf ("\n*******************************************\n");
  65.  
  66.   return (fclose (input) == 0);
  67. }
  68.  
  69. wchar_t *
  70. getuchar(){
  71. char *string=(char *) malloc (sizeof(char)*8);
  72. const char *tmp=string;
  73. char c=0;
  74. char c1=0;
  75. int i=1;
  76. wchar_t *dst=malloc(sizeof(wchar_t)*10);
  77. c1=getchar();
  78. string[0]=c1;
  79.  
  80. if (c1&128)
  81. c1=c1<<1;
  82. while (c1&128){
  83. c=getchar();
  84. string[i++]=c;
  85. c1=c1<<1;
  86. }
  87. string[i]='\0';
  88. mbsrtowcs(dst,&tmp,sizeof(tmp),NULL);
  89. return dst;
  90. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top