0 Replies - 337 Views - Last Post: 13 September 2007 - 09:37 AM Rate Topic: -----

#1 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6727
  • View blog
  • Posts: 31,156
  • Joined: 10-May 07

Append Decimals with Char.

Posted 13 September 2007 - 09:37 AM

Description: Use this in a loop when the char values will stay the same, but you need the decimal to increment.
#include <stdio.h>

int main(void) {
  int i=0;
  char filename[12]="filename";
  char buffer[254];

  for(i=0;i<10;i++) {
    sprintf(buffer,"%s%d",filename,i);
    printf("%s is your filenamen",buffer);
  }
}

Is This A Good Question/Topic? 0
  • +

Replies To: Append Decimals with Char.

#2 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6727
  • View blog
  • Posts: 31,156
  • Joined: 10-May 07

Re: Append Decimals with Char.

Posted 13 September 2007 - 09:37 AM

Description: Use this in a loop when the char values will stay the same, but you need the decimal to increment.
#include <stdio.h>

int main(void) {
  int i=0;
  char filename[12]="filename";
  char buffer[254];

  for(i=0;i<10;i++) {
    sprintf(buffer,"%s%d",filename,i);
    printf("%s is your filenamen",buffer);
  }
  return 0;
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1