VC 字符 文件名 动态 变长

Posted on 2012-03-14 23:44  无忧consume  阅读(183)  评论(0编辑  收藏  举报

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main()
{
  char filename[16] = "MHT";
  char *type = ".txt";
  char str[4];
  int i = 10;
  itoa(i, str, 10);
  printf("%s %d\n", filename, sizeof(filename)); //sizeof 全部长度
  printf("%s %d\n", filename, strlen(filename)); //strlen 实际字符个数
  strcat(filename, str);
  printf("%s\n", filename);
  printf("%s %d\n", filename, sizeof(filename));
  printf("%s %d\n", filename, strlen(filename));
  strcat(filename, type);
  printf("%s\n", filename);
  printf("%s %d\n", filename, sizeof(filename));
  printf("%s %d\n", filename, strlen(filename));
  return;
}

MHT 16
MHT 3
MHT10
MHT10 16
MHT10 5
MHT10.txt
MHT10.txt 16
MHT10.txt 9

Copyright © 2024 无忧consume
Powered by .NET 9.0 on Kubernetes