Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. int LlenarArreglo(int arreglo[], char nombre[]){
  5.  
  6. FILE *archivo;
  7. archivo= fopen(nombre,"r");
  8. if(archivo==NULL){
  9. return -1;
  10. }
  11.  
  12. int i,c;
  13. for(i=0;i<strlen(arreglo);i++){
  14. fscanf(archivo,"%d",&c);
  15. arreglo[i]=c;
  16. }
  17. fclose(archivo);
  18. return 1;
  19.  
  20. }
  21.  
  22. int main (){
  23.  
  24. int o;
  25. printf("Bienvenido a Tarea 3 Marly Riquelme Alarcon\n");
  26. printf("A continuacion elija una opcion\n");
  27. do{
  28. printf("1: Parte uno elegir valores desde valores.txt\n");
  29. printf("2: Parte dos elejir valores desde prueba.txt\n");
  30. printf("3: Salir\n");
  31. scanf("%d",&o);
  32. }while((o<1)||(o>3));
  33.  
  34. if(o==1){
  35. printf("Ha elegido 1, elejir valores desde valores\n");
  36. printf("ha continuacion se llnara el arreglo desde valores\n");
  37. int arreglo[50];
  38. int RespuestaUno = LlenarArreglo(arreglo, "valores.txt");
  39. if(RespuestaUno == 1){
  40. printf("El archivo valores.txt se ha encontrado con exito\n");
  41. printf("El arreglo es el siguiente\n");
  42. int i;
  43. for(i=0;i<strlen(arreglo);i++){
  44. printf("%d ", arreglo[i]);
  45. }
  46. printf("\n");
  47. }
  48. if(RespuestaUno== -1){
  49. printf("Eror al buscar el archivo valores.txt\n");
  50. }
  51. }
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement