Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ledmvl.c
- //
- // Copyright 2010 Serch <daemonfreedom.blogspot.com>
- //
- // This program is free software; you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation; either version 2 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program; if not, write to the Free Software
- // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- // MA 02110-1301, USA.
- #include <stdio.h>
- #include <string.h>
- char ruta[13];
- FILE *fp;
- int pedirNum();
- void abrir();
- int main(void)
- {
- int var;
- strncpy(ruta, "/dev/ttyUSB0", 13);
- if ((fp=fopen(ruta, "a"))==NULL)
- {
- fprintf(stdout, "No se puede abrir el archivo\n");
- return 0;
- }
- fcloseall();
- do
- {
- fprintf(stdout, "Introduce valor (0 para salir)\n");
- var =pedirNum();
- if (var==0)
- {
- abrir(); putc(0, fp); fclose(fp);
- break;
- }
- else
- {
- switch(var)
- {
- case 1: abrir(); fputc(1, fp); fclose(fp); break;
- case 2: abrir(); fputc(2, fp); fclose(fp); break;
- case 3: abrir(); fputc(3, fp); fclose(fp); break;
- case 4: abrir(); fputc(4, fp); fclose(fp); break;
- }
- }
- } while (1);
- return 0;
- }
- int pedirNum()
- {
- int valor;
- do
- {
- scanf("%d", &valor);
- } while (valor<0 || valor>4);
- return valor;
- }
- void abrir()
- {
- if ((fp=fopen(ruta, "w"))==NULL)
- {
- fprintf(stdout, "Imposible abrir el archivo\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement