Skip to content

Instantly share code, notes, and snippets.

@keita03301995
Created July 11, 2015 08:04
Show Gist options
  • Save keita03301995/4f46fc72f05073b978d5 to your computer and use it in GitHub Desktop.
Save keita03301995/4f46fc72f05073b978d5 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#define NUM 100
void write(FILE *fp);
int main(void)
{
FILE *fp;
fp = fopen("C:\\Users\\啓汰\\Downloads\\BC PAD\\課題12DataFile\\Kadai12G.txt","w");
if ( fp == NULL )
{
printf("エラー\n");
return 1;
}
write(fp);
fclose(fp);
return 0;
}
void write(FILE *fp)
{
int num,i,j;
char moji[NUM];
printf("文字列入力-->");
while ( scanf("%s",moji) != EOF )
{
i = 0;
while ( moji[i] != '\0' )
{
num = atoi(&moji[i]);
if ( num == 0 )
{
num = 1;
}
j = 0;
while ( num > j )
{
if ( num >= 1000 )
{
fprintf(fp,"%c",moji[i+4]);
}
else if ( num >= 100 )
{
fprintf(fp,"%c",moji[i+3]);
}
else if ( num >= 10 )
{
fprintf(fp,"%c",moji[i+2]);
}
else
{
if ( num > 1 )
{
fprintf(fp,"%c",moji[i+1]);
}
else
{
fprintf(fp,"%c",moji[i]);
}
}
j++;
}
if ( num >= 1000 )
{
i += 5;
}
else if ( num >= 100 )
{
i += 4;
}
else if ( num >= 10 )
{
i += 3;
}
else if ( num > 1 )
{
i += 2;
}
else
{
i++;
}
}
fprintf(fp,"\n");
printf("文字列入力-->");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment