Hello,
What's wrong with:
I get an infinite loop at the while statement.Code:int getLength(char* A){ int i = 0; while (*(A+i) != '/0') i++; return i;
Hello,
What's wrong with:
I get an infinite loop at the while statement.Code:int getLength(char* A){ int i = 0; while (*(A+i) != '/0') i++; return i;
Seems unlikely. What's the rest of the code?
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Code:char A[] = "Alice was beginning to get tired of sitting by her sister on the bank, and of having nothing to do."; int getLength(char* A){ int i = 0; while (*(A+i) != '/0') i++; return i; } int main(){ printf("%d\n",getLength(*A)); return 0;
Sorry, missed that you are using / instead of \ in what should be '\0'.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
What about this:
Code:void wrap(char* A, int m){ char* B = A; int n = getLength(B); int j,i; for (i=m; i<n; i+=m){ j = i+1; while (&(A+j) != " ") j--; //error &(A+j) = "\n"; //error } }
actually there should be * follow the pointer, but that gives a warning too.
You are using double quotes when comparing to a char. A char is in single quotes.
Operating Systems:
- Ubuntu 9.04
- XP
Compiler: gcc
why to mix pointer notation when you have index?
is a lot easier to readCode:A[j] != ' '
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
I'm wondering why this code gives bad access signal:
To me it should copy an array passed as A.
Code:void costCalc(char* A, int m){ char* B; int i=0; /*while (*(A+i) != '\0'){ *(B+i) = *(A+i); i++;}; *(B+i) = '\0';
This thread, ladies and gentlemen, is why you should compile with warnings on.
Quzah.
Hope is the first step on the road to disappointment.
Why this:
gives bad access signal when passed "aa" as char and n as 3?Code:void wrapper(char A[],int n, int m){ int i= 0; while (A[i] != ' ' && A[i] != '\0' && i<n) i++; //so from 0 to i we have the first word assuming we never start with a space, in case of "aa" returns 2 A[i] = '\n';
How are you calling the function - most likely, you are writing to a place in memory that isn't writable.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.