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;
Printable View
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
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
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.
why to mix pointer notation when you have index?
is a lot easier to readCode:A[j] != ' '
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.
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