Skip to main content
added 17 characters in body
Source Link
Mike
  • 48.7k
  • 30
  • 116
  • 179
char array[]="aabbcccd";
char type,*count,*cp=array;
while(cp!='\0'){ 

*cp is a pointer it's pointing to the address of the start of the array, it will never be == to a char '\0' so it can't leave the loop.

You need to deference the pointer to get what it's pointing at:

while(*cp != '\0') {
...

Also, you have a ; after your for loop, skipping the contents of it:

for(c=1;*cp==type;c++,cp++); <-- this ; makes it donot nothingexecute the code beneath it

After fixing both of those problems the code produces an output:

mike@linux-4puc:~> ./a.out 
a1b1c2cd

Not the one you wanted yet, but that fixes your problems with "printf not functional"

char array[]="aabbcccd";
char type,*count,*cp=array;
while(cp!='\0'){ 

*cp is a pointer it's pointing to the address of the start of the array, it will never be == to a char '\0' so it can't leave the loop.

You need to deference the pointer to get what it's pointing at:

while(*cp != '\0') {
...

Also, you have a ; after your for loop, skipping the contents of it:

for(c=1;*cp==type;c++,cp++); <-- this ; makes it do nothing  

After fixing both of those problems the code produces an output:

mike@linux-4puc:~> ./a.out 
a1b1c2cd

Not the one you wanted yet, but that fixes your problems with "printf not functional"

char array[]="aabbcccd";
char type,*count,*cp=array;
while(cp!='\0'){ 

*cp is a pointer it's pointing to the address of the start of the array, it will never be == to a char '\0' so it can't leave the loop.

You need to deference the pointer to get what it's pointing at:

while(*cp != '\0') {
...

Also, you have a ; after your for loop, skipping the contents of it:

for(c=1;*cp==type;c++,cp++); <-- this ; makes it not execute the code beneath it

After fixing both of those problems the code produces an output:

mike@linux-4puc:~> ./a.out 
a1b1c2cd

Not the one you wanted yet, but that fixes your problems with "printf not functional"

added 143 characters in body
Source Link
Mike
  • 48.7k
  • 30
  • 116
  • 179
char array[]="aabbcccd";
char type,*count,*cp=array;
while(cp!='\0'){ 

*cp is a pointer it's pointing to the address of the start of the array, it will never be == to a char '\0' so it can't leave the loop.

You need to deference the pointer to get what it's pointing at:

while(*cp != '\0') {
...

Also, you have a ; after your for loop, skipping the contents of it:

for(c=1;*cp==type;c++,cp++); <-- this ; makes it do nothing  

After fixing both of those problems the code produces an output:

mike@linux-4puc:~> ./a.out 
a1b1c2cd

Not the one you wanted yet, but that fixes your problems with "printf not functional"

char array[]="aabbcccd";
char type,*count,*cp=array;
while(cp!='\0'){ 

*cp is a pointer it's pointing to the address of the start of the array, it will never be == to a char '\0' so it can't leave the loop.

You need to deference the pointer to get what it's pointing at:

while(*cp != '\0') {
...
char array[]="aabbcccd";
char type,*count,*cp=array;
while(cp!='\0'){ 

*cp is a pointer it's pointing to the address of the start of the array, it will never be == to a char '\0' so it can't leave the loop.

You need to deference the pointer to get what it's pointing at:

while(*cp != '\0') {
...

Also, you have a ; after your for loop, skipping the contents of it:

for(c=1;*cp==type;c++,cp++); <-- this ; makes it do nothing  

After fixing both of those problems the code produces an output:

mike@linux-4puc:~> ./a.out 
a1b1c2cd

Not the one you wanted yet, but that fixes your problems with "printf not functional"

Source Link
Mike
  • 48.7k
  • 30
  • 116
  • 179

char array[]="aabbcccd";
char type,*count,*cp=array;
while(cp!='\0'){ 

*cp is a pointer it's pointing to the address of the start of the array, it will never be == to a char '\0' so it can't leave the loop.

You need to deference the pointer to get what it's pointing at:

while(*cp != '\0') {
...