Thread: can`t find mistake in this code

  1. #1
    Registered User
    Join Date
    May 2016
    Posts
    3

    can`t find mistake in this code

    Code:
    #include <stdio.h>#include <string.h>
    #include <stdlib.h>
    #include <time.h>
    #include <windows.h>
    #include <conio.h>
    #define b 13
    #define w 8        
     
    int a,j,i,index,remoe;
    char e;
     
     
     
    char *virk[b] = {"zilonis", "suns",
     "alnis", "zakis", "begemots",
     "lapsa", "dzeguze", "skudra", "vilks",
     "zirafs", "varna", "kakis","stirna"};
     
     
    char *random[w];
    char *uzd[w];
    char *arr[w];
     
     
                      
    void izvade(char *x){   
      printf("%8s\t",x); }           
          
     void nejausi (){
          srand(time(NULL));
          for (a=0;a<w;a++){
              j = rand() % b;
                *(random+a) = *(virk+j);
               izvade(*(random+a));}
         }
         
         
                                       
    void pajauta(){
     
    printf("No kura varda nodzest: ");
        scanf("%s", &index);
     
     
        
        printf("Cik nodzest:");
        scanf("%s", &remoe);
    }
    void dzesana(char random[w])  {
     
     
      for (i = 0; i < index-1; i++)
        random[w]= arr[i];
        for (j = index + remove - 1; j<w,j++,i++;)  
        {
        random[w] = arr[j];
        }
        for (i = 0; i < w - remove+1; i++)
        printf("%s ", random[w]);
    }
     
     
    main(){
     
                     
    for (a=0;a<b;a++)                                                                                  
        izvade(*(virk+a));
     
     
    cikls:
          
    printf("\n");
    printf("Tiek izvadits masivs ar nejausiem vardiem!");
    printf("\n\n");
     
    nejausi(); 
       
     
    printf("\n");
    getch();
    printf("\nVardi tiks nodzesti");
    printf("\n\n");
     
    pajauta();
     
    dzesana();
     
    izeja:
    printf("\n\n");
    printf("Vai Jus velaties atkartot?");
    printf("\n");
    printf("Ja(j) vai Ne(n)!");
    scanf("%s", &e);
    if (e=='j')goto cikls;
    else if (e=='n') exit(0);
    else goto izeja;
    getch();
    }

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,643
    Mistakes in your code:
    * terrible spacing
    * global variables
    * macro names in lowercase
    * use of goto
    * use of conio
    * main should be defined as explicitly returning an int and should return an int

    Mistakes in your question:
    * no actual question: you should say what you're trying to do and what the problem is
    * code should be pasted as plain text

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Perhaps you could explain the following:

    1. What is it supposed to do?
    2. What input are you giving it?
    3. What output are you receiving?
    4. What output are you expecting?
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  4. #4
    Registered User
    Join Date
    May 2016
    Posts
    3
    i have this char array:
    Code:
    char *virk[b] = {"zilonis", "suns", "alnis", 
    "zakis", "begemots", "lapsa", "dzeguze",
     "skudra", "vilks", "zirafs", "varna", "kakis","stirna"};
    and i need to delete elemts in user entered range
    for example from 3. to 5. element

  5. #5
    Registered User
    Join Date
    Jun 2015
    Posts
    1,643
    Post your code after fixing the above mistakes. Here's some more mistakes:
    * srand should be called as the first executable statement in main since it should generally only be called once in the run of a program.
    * This *(virk+j) is just silly. It should be virk[j].
    * Give your variables better names. E.g., what does b and w mean?

    And unless you can find help on a Latvian website it would be kind of you to translate it to English.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cant find my mistake on the code(matrix multiplication)
    By Paulo Esperon in forum C Programming
    Replies: 3
    Last Post: 02-23-2016, 09:11 PM
  2. sily mistake...cant find it!
    By brack in forum C Programming
    Replies: 2
    Last Post: 02-28-2011, 03:29 PM
  3. Find my mistake!
    By kacey in forum C Programming
    Replies: 4
    Last Post: 02-03-2011, 03:10 AM
  4. Find my mistake!
    By kacey in forum C Programming
    Replies: 2
    Last Post: 02-02-2011, 08:36 PM
  5. Can not find my mistake in this code?
    By BLG in forum C Programming
    Replies: 2
    Last Post: 09-04-2009, 04:19 PM

Tags for this Thread