ログイン
kid's world

文字列の操作

char s[10];
s = "ABC";
#include <stdio.h>

main()
{
  char *s1, *s2;
  
  s1 = "ABC\n";
  s2 = "DEF\n";
  printf(s1);
  printf(s2);
  
  s1 = s2;
  
  printf(s1);
}

/c/string-fig4.png

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

main()
{
  char *s1, *s2;
  
  s1 = "ABC\n";
  s2 = "DEF\n";
  printf(s1);
  printf(s2);
  
  strcpy(s1, s2);
  
  printf(s1);
}

/c/string-fig5.png

char s1[]="ABC", s2[]="DEF", s3[80];
s3 = s1 + s2;
strcpy(s3, s1);
strcat(s3, s2);
#include <stdio.h>
#include <string.h>

main()
{
  char s1[]="ABC", s2[]="DEF", s3[80];

  strcpy(s3, s1);
  strcat(s3, s2);

 printf(s3);
}
#include <stdio.h>

main()
{
   char s[200];
   
   scanf("%s", s);
}
#include <stdio.h>

main()
{
  char *s;

  scanf("%s", s);
#include <stdio.h>
#include <stdlib.h>

main()
{
  char *s;
  s=malloc(200);
  
  scanf("%s", s);
  
  free(s);
}

広告


©Toshio Koide 1996-2007.

mail.gif

広告