Adak 419 Nearly a Posting Virtuoso

It's standard, if not for beginners.

Three ampersand (star) programmers are generally mocked a bit, however.

Adak 419 Nearly a Posting Virtuoso

Your strings have no deep portions to them, so I'm confused. A deep part would be an array of pointers, where each pointer might point to a string, someplace else in memory.

You see deep structures commonly. The struct has a char * as one of the struct members.

Did you mean something like this?

/* pointer copy of a string */

#include <stdio.h>

int main() {
  char s1[]="What a great day to get out of a collapsed mine!";
  char s2[]="                                                ";
  char *sOne = s1;
  char *sTwo = s2;
  printf("\n\n");

  while(*sOne) {
    *sTwo++ = *sOne++;
  }
  printf("S1: %s   \nS2: %s", s1, s2);

  printf("\n\n\t\t\t     press enter when ready");
  (void) getchar();
  return 0;
}
Adak 419 Nearly a Posting Virtuoso

When you merged the arrays, you used pointers or indeces (int's usually), to help you do the merge.

Now, you can use that pointer or index, to temporarily hold (or point to) a value - now any of several in-place sorters will do what you want.

Adak 419 Nearly a Posting Virtuoso

You are clearing the screen, immediately AFTER you call the function!

Try clearing the screen BEFORE you call the function! ROFL! ;)

Adak 419 Nearly a Posting Virtuoso

HELP???

#include <stdio.h>
#include <math.h>
#include <string.h>

int main()
{
	FILE *inputfile, *infile;
	
	double mark;
	int grade;
???	int avg = 0.0;  
	int i = 0;
	char student[30];
	char filename[30];
	char *first, *last, *middle;

	printf ("Enter Name of Data File: \n");
	scanf ("%s", filename);

	inputfile = fopen( filename , "r");

Not "student". You will create "student" string. You need to take in %s %s %s for last
name, first name and middle initial. Also, last ) should go before "!".

???	while ((fscanf (inputfile, "%s", student) != EOF))<-Two } before !, one } here
	{
		for (i = 0;i>=0;i++)
		{
??? Move upward ^^			fscanf(inputfile, "%s %s %c", last, first, middle);

?? create student string, slightly better, imo.
	infile = fopen( strcat(first,last).dat, "r");

??? grade=0; grade != 0 ??? loop will never loop! Use another while loop, not 
a for loop if that helps your thinking. I would use a while loop.

???		for (grade = 0; grade != 0; grade++)
		{
			fscanf (infile, "%d", &mark);
??? You can't keep a sum building, when you're replacing the value with fscanf(),
each time through the loop. Use a sum variable: sum += mark;

???			mark = mark + mark;
			avg = mark/grade;
		}
		}
	}
	return 0;
}

If you type your own code tags, the slash on the closing tag is a / not a \.

Good start, but a few rough edges.

Adak 419 Nearly a Posting Virtuoso

You have to work out the simplest, clearest, and most efficient way to program.

#include <stdio.h>

#define SIZE 20

int main(void)
{
  int i = 0, n = i;
  int array[SIZE];
  int sum = 0;
  
  while (scanf("%d", &array[i]) !=0 ){
    printf("Entered Integer number %d: was %d\n", i, array[i]);
    sum += array[i];  //<----- add this line
    i++;
  }  
 
/* Right here, i equals the number of int's you have put into the array, so
the for loop below could be simplified n=0;n<=i;n++. However it shows an
even simpler and more efficient answer - put the sum into the same while()
loop as the entry (why the hell not?), and forget this second loop,
completely - it's useless. 
*/ 


//Ditch this loop like a bad habit :(
 for (i = 0; scanf("%d", &array[i]) == 0; i++){
   sum = sum +  array[i];
   printf( "The sum is: %d\n", sum);
   return (sum); //??? you're joking right?
  }      


  printf("The sum was %d", sum);      
  return 0;
}
Adak 419 Nearly a Posting Virtuoso

Setting your buffering for stdout depends on:

1) Your OS. It may set it as buffered or unbuffered. Unbuffered is preferred.
2) Your compiler Should have an "environmental" variable for this

3) You may be able to explicitly set or override it by:
a) putting a \n a the end of each printf(" <something> \n");
b: using setbuff();

#include <stdio.h>

/* BUFSIZ is defined in stdio.h */
char outbuf[BUFSIZ];  //for setting buffered output only

int main(void)
{
   /* attach a buffer to the standard output stream */
   setbuf(stdout, outbuf);
[B]   setbuf(stdout, NULL); //removes buffering from stdout[/B]

   /* put some characters into the buffer */
   puts("This is a test of buffered output.\n\n");
   puts("This output will go into outbuf\n");
   puts("and won't appear until the buffer\n");
   puts("fills up or we flush the stream.\n");

   /* flush the output buffer */
   fflush(stdout);

   return 0;
}

The above shows how to set, reset, and test buffering for stdout, for dos & Windows to XP.

If you're using Linux, ask in your Linux distro's forum or the general Linux forum. They're quite knowledgeable.

Adak 419 Nearly a Posting Virtuoso

You forgot the i++ in the first line of the for loop.

Adak 419 Nearly a Posting Virtuoso

The first problem I found is the while loop in main(). It has some nice bits of logic, but the overall program flow is flawed.


This is your while loop, with just a few changes:
1) The newline char is now removed from line[], right away
2) The FILE pointer you called "file", I changed immediately to "fp". Although C is case sensitive, I won't put up with that kind of name confusion.
3) I added the int variable j, and moved i and j declarations, to the top of the function.

The problem is that word[] was being sent to Palindrome(), and word[] had only one valid letter in it.

while((fgets(line,MAX,fp))){					//for some reason, this produces
		//int i;										//line of second mixed with first
		printf("%s\n",line);
		fflush(stdout);
		for(i = 0; line[i] != '\n'; i++){
			c = line[i];  //why assign an int, a char from the array of line?
      //remove the newline char:
      j = strlen(line);
      if((line[j-1])=='\n')
        line[j-1]='\0';

			if(isalpha(c)){
				word[wl] = c;
				wl++;
			}else{
				if(wl>0){
					word[wl] = '\0';
					printf("%s",word);			//for testing
					fflush(stdout);
					words++;
				}else{
					continue;					//if it's a single non-alpha
				}								//it's not a word
			}

			if(isPalindrome(word) == 0){ //not good here - word holds trash atm.
				new = (struct pal*)malloc(sizeof(struct pal));
				new->word = word;
				new->count = 1;
				if(front->count == -1){
					front = new;
				}else{
					new->next = front;
					front = new;
				}
			}

			wl = 0; //each letter then gets stuffed into word[0]
		}
	}

So Palindrome() is being called WAY too soon. …

mi.mac.rules commented: Great Advice! +1
Adak 419 Nearly a Posting Virtuoso

Dude, if you want help on the forum, then post your code on the forum. I went to your link and all I could do was get advertising and crap. Your file is apparently there, but you can't d/l it.

Get real if you want help.

Adak 419 Nearly a Posting Virtuoso

guess and tries should be int's - you'll never have .23 of either! ;)

Try adding a lo, mid, and hi variable. Then, when the guess is too high, bring down the hi variable to your current guess-1.

When your guess is too low, bring up your lo to your current guess+1.

mid will always start each loop with: mid = (lo+hi)/2

Adak 419 Nearly a Posting Virtuoso

Your input stream is still holding the newline char. Remove it by adding this:

(void) getchar();

After each time you're looking for a char input (getchar or scanf(%c)).

fflush(stdin) is non-standard, and generally doesn't work, because stdin is an input stream, not an output stream.

And Welcome to the forum, Caeon! ;)

Adak 419 Nearly a Posting Virtuoso

<nevermind>

Adak 419 Nearly a Posting Virtuoso

To find the center column for the first *, you can use either the number of rows in the "tree", or the number of *s, in the bottom row.

So if the bottom row has 7 *s, then 7/2 equals 3. So you should have 3 spaces before the * on the first row. You can use a for loop (outer one), to code this:

//handles the outer row configuration
for(numstars=1;numstars<=botmRow;numstars+=2) {
  numspaces = (botmRow - numstars)/2;

  //handles the spaces before the stars
  for(i=0;i<numspaces;i++)
    print one space here

  //prints out the star/s
  for(i=0;i<numstars;i++)
    print out star/s here
}

So the top row could be seen as:

spc spc spc * spc spc spc

because the top row will always have just ONE star. So all the other char's will have to be spaces. :)

Now for each row, the number of stars increases by 2, and that means the number of spaces on each side of the stars, will decrease by 1 (since there are two sides, and 2 * 1 = 2.

imo you don't want to use tabs for this assignment.

Adak 419 Nearly a Posting Virtuoso

Think of an old fashioned car odometer, with three wheels displaying their digit.

Now use three nested for loops, and don't over-complicate it. Let the loops do their magic. No if's, no else's, no bs. Easy as pie. ;)

int w1, w2, w3;  //wheel 1, wheel 2, wheel 3

for(w1=1;w1<10;w1++) {
  for(w2=1;w2<10;w2++) {
    for(w3=1;w3<10;w3++) {
      printf(\n %d %d %d", w1, w2, w3);
    }
  }
}

Try that, see if you understand it.

Adak 419 Nearly a Posting Virtuoso

Why aren't you including math.h?

Looks like an overflow problem, at first glance.

Adak 419 Nearly a Posting Virtuoso

Remove the first ++ from howlong++.

getch() returns it's value to the left hand side (the Lvalue), of the equation:

char1 = getch();
if(char1== 'p')
  break;

Would be how I'd do it. But there's another problem which is always present when scanf() is involved (potentially), and that is clearing out the newline char after the scanf(), prior to the scanf() for a char.

numbers are not bad, since scanf() will skip over a newline, but scanf() can't possibly skip over a newline when it's there to get a char - and this may be your real problem.

So add a getchar() just before the scanf() for the char, and see if that helps. This is UNDOUBTEDLY the most asked topic on the C forums, for beginners.

Since you can't see the newline on the keyboard buffer, it's a shock for C students to learn that scanf() leaves the newline in the kb buffer, and it causes problems, if you don't pull it off, (getchar() is one good way).

overall, don't get too addicted to scanf(). It's too "brittle" for user's to be trusted with.

Adak 419 Nearly a Posting Virtuoso

A very simple function. Here's a sample program:

#include <stdio.h>
#include <string.h>

int main() {
  int i, j, temp; 
  char s[]="Once a jolly swagman";
  i=0;
  j=strlen(s) - 1;  

  while(i < j) {
    temp = s[i];
    s[i++] = s[j];
    s[j--] = temp;
  }
  printf("\n\n New string is: %s", s);

  printf("\n\n\t\t\t     press enter when ready");
  i = getchar();
  return 0;
}
Adak 419 Nearly a Posting Virtuoso

Have you tried testing the return from sscanf() ?

When it return anything less than 1, you should be at the end of the file - or at least something stopped sscanf() from working right.

It is frustrating how you have to "dance around" to do such a simple thing.

creeps commented: I love to hate the last sentence :) +1
Adak 419 Nearly a Posting Virtuoso

If a program that compiles and runs, doesn't give the right answer, I put everything up as a suspect. Naturally, you want to prioritize the suspect list for checking, and logic errors are far more common, but "always" things, still make the bottom of my "to be checked" list.

You might think my list is nit-picking, but I can assure you, my programs have no lice! ;)

Adak 419 Nearly a Posting Virtuoso

Two things:

1) If your compiler is Turbo C, you won't load the floating point package you need, with that code. You need to have at least one of the doubles assigned an initial value of 0.0.

(since TC's float package can be stubborn about this, post back if you're still stuck and I'll give you some code guaranteed to force it to be loaded. The above should do it, however.)

2) pow() expects two doubles as parameters. You're giving it one double, and one integer, instead. Whether that works or not, depends on the relative sizes of integers and doubles, and your compiler design.

See if the above solves your problem.

Adak 419 Nearly a Posting Virtuoso

This isn't a full program, and it's VERY rough, but it shows the logic that would be hard to understand in pseudo code. I would use logic like this.

#include <stdio.h>
#include <string.h>

int main() {
  int i, j, digit, len, num, power; 
  char snum[10]={"1234"};
  char ans[100]={""};
  char pwr[4][10]={ {"one"}, {"ty"},{"hundred"},{"thousand"} };
  char wrd[20][20]={ {"zero"}, {"one"},{"two"},{"three"},{"four"},{"five"},
  {"six"},{"seven"},{"eight"},{"nine"},{"ten"},{"eleven"},{"twelve"},{"thirteen"},{"fourteen"},
  {"fifteen"},{"sixteen"},{"seventeen"},{"eighteen"},{"nineteen"} };
  // 012345678901234567890123456789012345678901234567890
  //(seventy seven thousand seven hundred, seventy seven) -- 50 char's
  // 15 spaces before thousands, 30 before hundreds

//  Marked out while debugging, only:
//  printf("\n\n Enter a number from 0 to 10,000: ");
//  scanf("%s", snum);
//  i = getchar();  
  
  printf("\nNumber is: %s", snum);
  len = strlen(snum);
  j=0;

  for(i=0;i<len;i++) {
    digit=snum[i]-'0';   //get the next digit from the string
    strcpy(&ans[j], &wrd[digit][0]);  //use it as an index to the wrd array
    j += strlen(wrd[digit]);       //adjust j;
    ans[j++]=' ';                //remove end of string marker char and j++

    //add the right power word here  //unfinished

  }
  printf("\n\n Answer: %s", ans);

  printf("\n\n\t\t\t     press enter when ready");

  i = getchar(); ++i;
  return 0;
}
Adak 419 Nearly a Posting Virtuoso

I'd be tempted to use a small 2D word array:

powr[] array:
[0]="teen"
[1]="ty"
[2]="hundred"
[3]="thousand"
etc.
wrd[] array:
0="zero"
1="one"
2="two"
etc.

and this might easily change. I'm not familiar with this exercise.

and put together the string answer, from big to small number values:
ans[100]={""};
and use a small char array for the number, itself:
snum[10]={""};

You know how to "peel" off the digits, so that could be useful
As much as possible, I'd want to use the association of the pwr and wrd array index, with the right word, instead of long lines of explicit code. Go Loops! ;)

Some explicit code will be needed, I believe, but limit it.

Let me mess around with this a bit. Thinking along more representative lines of working with this problem, what do you see?

99% of the time, when you feel the code is just being pedantic as hell, you're right - it is, and it needs a better algorithm. You're there, I can tell. ;)

P.S: *IMPORTANT*
If you want people on the forum to study your code - highlight it, and click on the

icon at the top of the editing window.

Otherwise your code looks like html crap, and is very hard to even look at, let alone study. ALWAYS USE CODE TAGS around your code.[code]
icon at the top of the editing window.

Otherwise your code looks like html …

Adak 419 Nearly a Posting Virtuoso

I typed the flipping wrong WORD - should have been "typedef", not typecasting!

/face palm

Adak 419 Nearly a Posting Virtuoso

I appreciate your explanation, Narue. I learned from two books, primarily:
"The C Programming Language" - K&R and "Beginning C" - Horton.

Both describe typedef as making a "synonym" or "another name", for a data type: K&R p.146, Horton, p.416., but they're much more than just a define, and that would include casting characteristics.

Casting is something I'm just abysmal with, on the whole. The less I have to do it, the happier I be. ;)

Adak 419 Nearly a Posting Virtuoso

I'm assuming he's not a brain dead yokel that just fell off the turnip truck yesterday, and will adjust MaxLength to whatever size he needs.

Of course.

Adak 419 Nearly a Posting Virtuoso

Using fgets(), with the 30-1, there is NO chance of a buffer over-run. None!

You can press keys until you're blue in the face, and it won't accept any more char's.

Adak 419 Nearly a Posting Virtuoso

He doesn't need to change the size of his array - just use the code like I posted. There are very few words longer than 30 char's, but he can make it more than 30 if he needs it.

it's not bad practice - you're not seeing what I'm suggesting, or you wouldn't be harping on this. Didn't you see "MaxLength" in my code I posted earlier?

C'mon - tick tock, hop on board, train she is a'moving.

Yeah, I saw your good suggestion on the sort problem, but I had already posted before I read through your post.

You know as well as I do that if you absolutely want to save the maximum amount of space, and still get every long word, you would use a "ragged" 2D pointer array. It's just a bit above his skill level atm, and may be more than he needs, anyway.

Adak 419 Nearly a Posting Virtuoso

No. ;)

He can use your fgets() suggestion, to limit the number of char's that can be input. There is no need to use the "input" array, AFAIK.

He should definitely keep the 2D word array, and it is certainly NOT "bad" practice.

He has some other code that is useless, such as the loop with "count", that isn't needed. Whether the string contains spaces or not won't matter with fgets():

int numNames, MaxLength=30;
printf("\n How many names do you want to enter? [1-10] ");
scanf("%d", &numNames);
getchar();  //remove the leftover '\n'
for(i=0;i<numNames;i++) 
  fgets(word[i], MaxLength-1, stdin);

After that, sorting the strings is straight forward. I pointed out his mistake earlier in his sorting.

If he has any problems I'll be glad to sort out his sort, again. ;)

Adak 419 Nearly a Posting Virtuoso

Well, casting is not the same thing as typecasting. Typecasting just creates an "alias" (another name), your program can use, for a certain datatype (typically a struct name).

A cast in C is redundant, generally. It doesn't hurt to make them (if you're very careful to make it right), but it can 1) hide an error (when you forget to include stdlib.h), and 2) gives you a chance of goofing it up.

On RARE occasions, you will need to cast the return from malloc(), but it IS very rare.

Auhors (as you will see when you have more experience), are not necessarily good programmer's, and have taken their code (with slight modifications), from others, or have not updated their programming skills since Christ was a corporal, or it's just an error, or whatever. Gods of programming, they are not.

Get a copy of "The C Programming Language" by Kernighan and Ritchie, (second or latest edition), and you'll have the bible of C programming, straight from the creators of the language.

Adak 419 Nearly a Posting Virtuoso

ddd ccc eee is not in sorted order, so I'm not sure if you want to sort in ascending or descending order.

You should keep the 2D array, no need to change that.

you can't use temp like you have it in the sort portion. When you assign it to the address for string1, that's fine.

But then you strcpy string2 into string1! Guess what temp is pointing to NOW?

Then you're putting string2 right back into string2 with the final assignment from temp to string2.

Print out your sort when it swaps, and see it. Put in a getchar() to stop it after every swap, if you don't step through it with watches set.

Better to make temp an array, instead of a ptr, imo.

smith32 commented: Thz to u.... ur solution is more suitable to me +2
Adak 419 Nearly a Posting Virtuoso

No casting or typecasting is needed for malloc(). It returns a void pointer which the program will automatically change to the right type, for you. Very rarely, you'll need to do a cast of the pointer, manually.

You need to include stdlib.h for malloc to work.

If you need more help, catch some of the excellent tutorials on line from Google, or post up your code, so we can see WTF you're trying to do, and give specific advice.

Advice like this is never great, because it can't be nearly as thorough as a tutorial dedicated to the subject, and it can't be very specific, because there is no code.

Adak 419 Nearly a Posting Virtuoso

If you have a number in base 10 (normal base), and use the mod operator on it, what do you get?

int number = 123;
printf("\n %d", (number % 10));

now divide the number by 10. You've now "peeled off" the right most digit from the number.

You can continue doing this in a loop, until the number disappears. Save the first and the last digit, and there you go.

If you need any more help with your program, post your code so we can see the details of what you're referring to. Doesn't have to be the whole program, but at least the part you're referring to.

AND do use code tags around any posted code - please!

Adak 419 Nearly a Posting Virtuoso

You need to ask questions about your program, rather than posting your assignment and saying "thanks" for the solution.

It is your assignment, after all. You won't learn by not working with it.

And Welcome to the Forum, Ahmed! ;)

Adak 419 Nearly a Posting Virtuoso

Here's one big error:

scanf("%s",inpt_str1);

   for(i=0;inpt_str1[i]!='\n';i++)
    {
      len1+=1;
      concat_str[i]=inpt_str1[i];
    }

scanf() does NOT include the newline char, into the string - that's fgets(). scanf() (infamously!) leaves the newline behind.

So there is no stopping your loop. Change the '\n' to '\0' (the end of string marker) (which scanf() DOES include, for strings.

You do this same error in two places, at least.

Adak 419 Nearly a Posting Virtuoso

If you're taking a class, use the compiler that the teacher will be testing you and your programs, with. There are two highly rated free C compilers that I know of. One is Microsoft's Visual Express (Google for a d/l site). The video is helpful to d/l as well.

The other is MingGW compiler, with Code::Blocks IDE. Google "Code::Blocks" for more info.

Turbo C won't handle newer C functions, or large memory demands, but it is simpler to use. It will easily handle simple graphics and non-buffered input, that both the above, will handle only with some difficulty.

Although I can't recommend Turbo C, I confess to using it with pleasure, for small stuff.

Narue has the pointer problem covered, below - typing slow, today.

Adak 419 Nearly a Posting Virtuoso
#include<stdio.h>


int main()
{
  int nr_products, nr_prices, price, over10=0;
  char product[40]={'\0'};

  printf("Enter the number of products");
  scanf("%d",&nr_products);
  getchar();

  printf("Product:");//enter the product
  fgets(product, sizeof(product), stdin);

  printf("Price:");//enter price
  scanf("%d",&price);
  getchar();
  for(i=0; i<nr_products;i++) 
  { 
    if(price>10)//condition over 10
    {
      printf("\nThis product has a price over 10: %s",product);//product over 10
      over10++;
    }	
  }
  if(over10==0) 
  { 
    printf("\nNo product cost over 10."); 
  }
  else {
    if(over10==1)
      ch='';
    else
      ch='s';
    printf("%d product%c cost over 10.", over10, ch);
  }
  return 0;
}

Not a complete solution to what you need perhaps, but a good start. I have not tested/debugged any of the above.

Adak 419 Nearly a Posting Virtuoso

The program uses nr_products and nr_prices, without having given them values! :(
These variables were declared BUT NOT initialized to any value.

if statements need TWO == in them, instead of just one =.

You need a for loop (best) to control how many times a price needs to be entered.

products should be a string, instead of just one char.

Lots of work to do on this program.

Adak 419 Nearly a Posting Virtuoso

Most compiler's have a default return type of int - like Borland used to.

Today, you should be explicit about your return types, and they should be included in your function prototype.

What is the return good for?

Any answer to a computation the function is doing! Serious programming doesn't use much in the way of global scoped variables - they're local 99% of the time. A return is ONE way (a pointer to the variable being passed as a parameter to the function is another way), to bring the answer back to the calling function.

Adak 419 Nearly a Posting Virtuoso

Glad it worked out.

Adak 419 Nearly a Posting Virtuoso

Try changing "char" to "unsigned char".

BTW this code is almost letter for letter, right out of "The C Programming Language, by Kernighan and Ritchie, page 103. That's the "Bible" for C programming. Only difference is the return is int in the book.

(and ptr instead of p as the name of the pointer).

And WTF compiler are you using? I want to burn it at the stake!! ;)

Adak 419 Nearly a Posting Virtuoso

I believe this is what your teacher wants:

size_t MyStrlen(const char *s1) {
  char *ptr = s1;
  
  while(*ptr != '\0')
    ptr++;
  
  return ptr - s1;
}

Which is the same thing your function was doing, but using only pointers.

I'm used to seeing the return from this, being an int, instead of a size_t, but no matter. If you have trouble getting the size_t to print out right, then just cast it to an int, in the printf() statement.

Adak 419 Nearly a Posting Virtuoso

You're welcome, guy.

When it refers to "that variable", it is not describing the "other variable". Teacher's description has jumped back to refer to the si variable.

So you're OK on that point.

What you're not OK on is the use of pointers++. Teacher doesn't want size_t input++ at all.

I'm going to post this, and read just a bit of code.

Adak 419 Nearly a Posting Virtuoso

Logically, you don't need anything else - especially not another const char *.

Can you post the EXACT assignment - something has been misunderstood, I believe.

Adak 419 Nearly a Posting Virtuoso

To do what you are doing so far, you don't need to change anything except get the right identifier for your size_t to print out OK.

If you can't find it at all, then yes - cast it to an unsigned int and use %u

Adak 419 Nearly a Posting Virtuoso

In your compiler's help files, look up what the correct format identifier is, for size_t.

For me, it's an unsigned int. For you, it could be an unsigned long "%lu", or an unsigned short "%hu", or even have a unique identifier, all it's own.

There are a BUNCH of format identifiers for printf. Also, it has length modifiers, like the "h" in "%hu", that I mentioned just before.

Find that right identifier and length (if length is needed), and you'll be good to go. If you can't find it - Google it, and be sure to mention your compiler's name in your search on Google.

Edit:
P.S. s1 IS a const char *, because the s1 string is only measured - not changed. si is just ONE parameter (even though it has two words to describe it).

Adak 419 Nearly a Posting Virtuoso

To be consistent, I would:

1) remove the cast to int, in the printf() statements
2) change int input to size_t input, in the MyStrLen() function

and

3) use %u for the format identifier in the printf() statements.

That works for me, with no errors or warnings, and gives correct results.

Adak 419 Nearly a Posting Virtuoso

You were posting your updated code, at the same time I was writing my post - and looking at your first post, only. I was also looking into my header files on "size_t", which is why my post was so much later than yours (although the post was started before you finished).

Which not only confused you and I, but the forum software, as well (I wound up with a double post).

Did you try %u, and what is your compiler?

Adak 419 Nearly a Posting Virtuoso

<moderator, please delete>

Adak 419 Nearly a Posting Virtuoso

I have some idea's for fixing it, but that's NOT the code that you posted!

I can't fix code that I can't see -- trust me on this.;)

Post the code that you tried, and got this error on, and tell me what compiler you're using, and the answer shouldn't be too difficult.

(Basically, the error is quite right - %d is for int's. size_t will be an unsigned int, so try using %u).