0

hi guys im wrote testing program to test features for my function and there is only 7 iterations in my for cicle but i malocc`ed more then that tell me why pls(testing string was andrew8mike)

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>

int main(void)
{
    int x = 0;
    char* name;
    name = (char*)malloc(sizeof(char) * 10);
    {
        printf("Whats your name:\n");
        scanf("%s",name);
    }
    for(int i = 0;i < sizeof(name);i++)
    {
        if(isdigit(name[i]) && isdigit(name[i+1]))
        {
            x = atoi(&name[i]);
            break;
        }
    }
    {
        printf("there is digit in your name:%i\n",x);
    }
}
1

Here's a problem: sizeof(name). name is a pointer, sizeof(a pointer) is 8. You probably want the length of name. (Think strlen included in string.h).

1
  • ok now thats embarrassing i mixed up functions lol but thanks anyway mate
    – Andrew
    Jul 26 '17 at 13:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .