I am trying to write a function to get string length without using any library functions and with using pointers.
I am obviously quite a novice in programming so please help!
//function declarations.
#include <iostream>
int sizeofstring(char *given);
void main()
{
int answer1 = 0;
char *fivep = "abcde";
char *sixp = "abcdef";
answer1 = sizeofstring(fivep);
printf("-> %d\n", answer1);
}
int sizeofstring(char *given)
{
int counter = 0, a = 0;
for (a = 0; given[a] != '/0'; a++)
{
counter = counter + 1;
}
return counter;
}
I have fixed many problems but it seems like pointer is killing me now...
As soon as I compile it, it will just crash without telling me why.
Help please... All is lost for me.