Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "wchar.h"
- #include <stdlib.h>
- void ostdin ();
- int ofile (char *filename);
- wchar_t * getuchar();
- int
- main (int argc, char *argv[])
- {
- if (argc == 1)
- {
- printf ("Nie podano żadnych argumentów\n");
- ostdin ();
- }
- else if (argv[1][0] == '-')
- {
- if (argv[1][1] == '\0')
- {
- printf ("Jako argument podano '%s'\n", argv[1]);
- ostdin ();
- }
- else
- printf ("Błąd!\nPodano zły argument\n");
- }
- else
- {
- if (ofile (argv[1]) == -1)
- printf ("Błąd!\nNie udało się otworzyć pliku \"%s\"\n", argv[1]);
- }
- return 0;
- }
- void
- ostdin ()
- {
- wchar_t *test;
- printf ("Program odczytuje standardowe wejscie (stdin)\n");
- printf ("*******************************************\n");
- while (test=getuchar()){
- printf("Znak = ");
- fputws(test,stdout);
- printf("\n");
- }
- }
- int
- ofile (char *filename)
- {
- int c;
- FILE *input = fopen (filename, "r");
- if (input == NULL)
- return -1;
- printf ("Program odczytał plik o nazwie \"%s\"\n", filename);
- printf ("*******************************************\n");
- while ((c = fgetc (input)) != EOF){
- putchar (c);
- printf("\n");
- }
- printf ("\n*******************************************\n");
- return (fclose (input) == 0);
- }
- wchar_t *
- getuchar(){
- char *string=(char *) malloc (sizeof(char)*8);
- const char *tmp=string;
- char c=0;
- char c1=0;
- int i=1;
- wchar_t *dst=malloc(sizeof(wchar_t)*10);
- c1=getchar();
- string[0]=c1;
- if (c1&128)
- c1=c1<<1;
- while (c1&128){
- c=getchar();
- string[i++]=c;
- c1=c1<<1;
- }
- string[i]='\0';
- mbsrtowcs(dst,&tmp,sizeof(tmp),NULL);
- return dst;
- }
Add Comment
Please, Sign In to add comment