(问)将文件分成一些文件 [英] (ask) divide file into some file

查看:72
本文介绍了(问)将文件分成一些文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以在这里,我真的不知道如何编程



这里的问题:



我有一个文件.txt格式,其中有许多数字顺序关闭。

例如:

+1

+2

+3

+4

+5

等......



例如:我的数据有100个数字下降,我必须将它们分成10个部分。之后该文件变为10文件.txt格式,其中有1 - 10(第一部分),11 - 20(第二部分),21 - 30等......


,程序必须用C ++编写。感谢您的帮助

解决方案

我在C中编码,

 #include <   stdio.h  >  
#include < span class =code-keyword>< stdlib.h >
#include < string.h >

int main(int argc,char ** argv){
int i,j;
char filename [6],context [10];
strcpy(filename,0.txt);
freopen(input.txt,r,stdin);
for(i = 0; i < 10; i ++){

filename [0] =' 0' + i;

freopen(filename, w,stdout);

for(j = 0; j< 10; j ++){

< span class =code-attribute> scanf(%s,context);

< span class =code-attribute> context [strlen(context)] =' \ n' ;

< span class =code-attribute> printf(%s,context);

< span class =code-attribute> }

< span class =code-attribute> }

return 0;

}





C ++是一样的。


这应该可以帮助你:

http://msdn.microsoft.com/en-us/library/vstudio /y52yxde8.aspx [ ^ ]



如果你使用谷歌 [<一个HREF =https://www.google.com/search?q=microsoft+C%23+read+a+file&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla :NB-NO:官方&安培;客户=火狐-A#HL =否安培;安全=关&安培;客户=火狐-A和HS = ZCM&安培; RLS = org.mozilla:NB-NO%3Aofficial&安培; sclient = PSY-AB&安培; q =微软+ C%2B%2B +读+ A +文件&安培; OQ =微软+ C%2B%2B +读+ A +文件&安培; gs_l = serp.3 ... 18852.19399.0.19886.3.3.0.0.0.0.101.275 .2j1.3.0 ... 0.0 ... 1c.1.7.psy-ab.ntq_bQ2iNos&安培; PBX = 1&安培; BAV = on.2,or.r_cp.r_qf&安培; BVM = bv.44158598,d.bGE&安培; FP = ec9a8850ed01a83a& biw = 1850& bih = 994target =_ blanktitle =New Window> ^ ]


查看 https://www.google.com/search?q=C%2B%2B+read+a+file [ ^ ] for generic C ++

so here it is, I really dont know how to program

here the problem :

I have a file .txt format, in which there are many number sequentially down.
for example :
+1
+2
+3
+4
+5
etc...

eg: my data have 100 number down, I have to divide them into 10 parts. later the file become 10 file .txt format, in which there are number 1 - 10 (part one), 11 - 20 (part two), 21 - 30, etc ...

and the program must be made from C++. Thanks for help

解决方案

I code it in C,

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

int main(int argc, char** argv){
        int i,j;
        char filename[6],context[10];
        strcpy(filename, "0.txt");
        freopen("input.txt","r",stdin);
        for(i=0; i<10; i++){

                filename[0] = '0'+i;

                freopen(filename,"w",stdout);

                for(j=0; j<10; j++){

                        scanf("%s",context);

                        context[strlen(context)] = '\n';

                        printf("%s",context);

                }

        }

        return 0;

}



C++ is the same.


This should get you on your way:
http://msdn.microsoft.com/en-us/library/vstudio/y52yxde8.aspx[^]

There should be lots of options if you use Google[^]


Check out https://www.google.com/search?q=C%2B%2B+read+a+file[^] for generic C++


这篇关于(问)将文件分成一些文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆