前提・実現したいこと
8タブで文字を出力したいのですが、うまくいきません。エラーメッセージはでないのですが、どこが間違っているのか解説していただけると有り難いです。
該当のソースコード
c
1#include<stdio.h> 2#include<stdlib.h> 3#include<string.h> 4void detab(FILE *src,FILE *dst,int width){ 5 int ch,pos=1; 6 while((ch=fgetc(src))!=EOF){ 7 int num; 8 switch(ch){ 9 case '\t': 10 num=width-(pos-1)%width; 11 for( ;num>0;num--){ 12 fputc(' ',dst); 13 pos++; 14 } 15 break; 16 case '\n': 17 fputc(ch,dst);pos=1;break; 18 default: 19 fputc(ch,dst);pos++;break; 20 } 21 } 22} 23int main(void){ 24 int width=8; 25 detab(stdin,stdout,width); 26 return 0; 27}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。