0

This is function for show how many times are some numbers in string,but 2D array dont work for me string is like a Fift Evenue 45/01 and in hist_arr must be on possition

0-1
1-1
2-
3-
4-1
5-1
6-
7-
8-
9-
void funkcia_h(char **arr,int rows)
{
    int i,j,*his_arr;
    int input;
    long value;
    char *ptr;
    scanf("%d",&input);
    his_arr = (int *)calloc(10,sizeof(int));
    for(i=0;i<rows;i++)
        for(j=0;j<20;j++)
        {
            if(i == input)
            {
                value = strtol(arr[i][j],&ptr,10);//dont work
                value = atoi(arr[i][j]);//dont work
                if(value >= 0 && value <= 9)
                {
                    his_arr[value]++;
                }
            }
        }
}
Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
Da No
  • 69
  • 2
  • 10
  • Note that `input` can be used uninitialized in your program, also you can do a `NULL` dereference, that is undefined behavior and it's bad. – Iharob Al Asimi Apr 07 '15 at 11:53
  • char** aloc2D(int rows) { int i; char **arr; if((arr=(char**)malloc(rows*sizeof(char*)))==NULL) { printf("Error\n");exit(1); } for(i=0;i – Da No Apr 07 '15 at 12:02
  • char ** funkcia_n(FILE *fr,int rows) { int i,j; char **arr; otvor(&fr);//openfile arr = aloc2D(rows); for(i=0;i – Da No Apr 07 '15 at 12:03

0 Answers0