Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

learning c

Name: RandomJavaGuy 2013-10-19 17:23

Hello. i am trying to write a simple program in c that will read field of chars(aaabbbaaa) and than an interval and than it will find out the number of neighboring same chars in the interval and print it.
   char field[256];
   scanf("%s" , field);
   int start;
   int end;
   scanf("%d %d", start, end);
   int neighbors = 0;
   for(int i=start;i<end;i++)
    {
        if(field[i]==field[i+1])
        {
            neighbors++;
        }
    }
    printf("%d", neighbors);

Name: RandomJavaGuy 2013-10-19 17:26

Where am i doing a mistake?

Name: Anonymous 2013-10-19 17:38

back to >>>java

Name: RandomJavaGuy 2013-10-19 17:45

OHHH. Thanks 4 advice dude.

Name: Anonymous 2013-10-19 20:50

    scanf("%d %d", start, end);

scanf takes pointers. Arrays are passed by pointer, but ints are not. You need to use the unary & operator here.

Also, buffer overflows eww

Name: Anonymous 2013-10-20 11:40

than
than
than
What the fuck are you trying to say?

Name: Anonymous 2013-10-20 11:53

>le pedophile sage

Don't change these.
Name: Email:
Entire Thread Thread List