[C]把一堆没有换行的 姓名 字符串文件,改成有换行的

在这里插入图片描述
https://wenku.baidu.com/view/a47e7271650e52ea551898ab.html

要做工卡了,要取英文名了。

百度文库这玩意儿不充钱不能复制就很烦,关掉JS后,复制完没有回车换行。。。。。。。。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
int main()
{

/*
读取文件结果:
AaronAbbottAbelAbnerAbrahamAdairAdamAddisonAdolphAdonisAdrianAhernAlanAlbertAldrichAlexanderAlfredAlgerAlgernonAllenAlstonAlvaAlvinAlvisAmosAndreAndrewAndyAngeloAnselAntoineAntonioAntonyArcherArchibaldAriesArlenArmandArmstrongArnoArnoldArthurArvinAsaAshburAtwoodAubreyAugusAugustAugustineAveryBairdBaldwinBancroftBardBarlowBarnettBaronBarretBarryBartBartholomewBartleyBartonBasilBeacherBeauBeckBenBenedictBenjamin?BennettBensonBergBergerBernardBernieBertBertonBertramBevisBillBingBishopBlairBlakeBlitheBobBoothBorgBorisBowenBoyceBoydBradleyBradyBrandonBrianBroderickBrookBruceBrunoBuckBurgessBurkeBurnellBurtonByronCaesarCalvinCareyCarlCarrCarterCashCecilCedricChadChanningChapmanCharlesChaselChesterChristChristianChristopherClareClarenceClarkClaudeClementClevelandCliffCliffordClydeColbertColbyColinConradCoreyCorneliusCornellCraigCuritisCyrilDanaDanielDarcyDarnellDarrenDaveDavidDeanDempseyDennisDerrickDevinDickDominicDonDonahueDonaldDouglasDrewDukeDuncanDunnDwightDylanEarlEdEdenEdgarEdisonEdmundEdwardEdwiinEgbertEliElijahElliotEllisElmerElroyEltonElvisEmmanuelEnochEricErnestEugeneEvanEverleyFabianFelixFerdinandFitchFitzgeraldFordFrancisFrankFranklinFredericGabrielGaleGaryGavinGeneGeoffGeoffreyGeorgeGeraldGilbertGilesGlennGoddardGodferyGordonGregGregaryGriffithGroverGustaveGuyHaleHaleyHamiltionHardyHarlanHarleyHaroldHarrietHarryHarveyHaydenHeatherHenryHerbertHermanHilaryHiramHobartHoganHoraceHowarHuberyHughHugoHumphreyHunterHymanIanIngemarIngramIraIsaacIsidoreIvanIvesJackJacobJamesJaredJasonJayJeffJeffreyJeremyJeromeJerryJesseJimJoJohnJonasJonathanJosephJoshuaJoyceJulianJuliusJustinKellyKenKennedyKennedyKennethKentKerrKerwinKevinKimKingKirkKyleLambertLanceLarryLawrenceLeifLenLennonLeoLeonardLeopoldLesLesterLeviLewisLionelLouLouisLucienLutherLyleLyndonLynnMageeMalcolmMandelMarcusMaricoMarkMarlonMarshMarshallMartinMarvinMattMatthewMauriceMaxMaximilianMaxwellMeredithMerleMerlinMichaelMichellMickMikeMilesMiloMonroeMontagueMooreMorganMortimerMortonMosesMurphyMurrayMyronNatNathanNathanielNeilNelsonNewmanNicholasNickNigelNoahNoelNormanNortonOgdenOliverOmarOrvilleOsbornOscarOsmondOswaldOtisOttoOwenPaddyPageParkerPatrickPaulPaynePerryPetePeterPhilPhilipPorterPrescottPrimoQuennelQuentinQuincyQuinnQuintionRachelRalapRandolphRaymondRegReganReginaldReubenRexRichardRobertRobinRockRodRoderickRodneyRonRonaldRoryRoyRudolfRupertRyanSamSampsonSamuelSandySaxonScottSeanSebastianSidSidonSidneySilvesterSimonSolomonSpencerStanStanfordStanleyStevStevenStewardTabTaylorTedTernenceTheobaldTheodoreThomasTiffanyTimTimothyTobiasTobyToddTomTonyTracyTroyTrumanTylerTyroneUlyssesUptonUriahValentineValentineVerneVicVictorVincentVirgilVitoVivianWadeWalkerWalterWardWarnerWayneWebbWebsterWendellWernerWilburWillWilliamWillieWinfredWinstonWoodrowWordsworthWrightWytheXavierYaleYehudiYorkYvesZacharyZebulonZiv
*/
	FILE *frp = NULL;
	char *ibuff=NULL;
	char *obuff=NULL;
	frp = fopen("./name.txt", "r");
	
	/*判断文件大小*/
	fseek(frp, 0, SEEK_END);
	int len = ftell(frp);
	printf("length is %ld\r\n", len);
	
	
	fseek(frp, 0, SEEK_SET);
	ibuff=(char*)malloc(len*sizeof(char)+1);
	fscanf(frp, "%s", ibuff);
	printf("%s\n", ibuff );
	fclose(frp);

	int cnt=0;
	for(char *tmp=ibuff; 0!=*tmp; tmp++) if(isupper(*tmp)) cnt++;
	unsigned long long malloc_size=len*sizeof(char)+1/*+cnt*/+cnt;
	obuff=(char*)malloc(malloc_size);

	/*嵌入换行\r(\r不要也可以)回车\n*/
	char *itmp=ibuff;
	char *otmp=obuff;
	*otmp=*itmp;
	itmp++;
	otmp++;
	while(0!=*itmp)
	{
		if(isupper(*itmp))
		{
//			*otmp='\r';
//			otmp++;
			*otmp='\n';
			otmp++;
		}
		*otmp=*itmp;
		itmp++;
		otmp++;
	}

	printf("%s", obuff);

	/*写入文件*/
	FILE *fwp;
	fwp = fopen("./output_name.txt", "w+");
	if( fwp == NULL )
	{
		fprintf(stderr, "Value of errno: %d\n", errno);
		fprintf(stderr, "Error opening file: %s\n", strerror(errno));
		return 0;
	}
	fwrite(obuff, malloc_size, 1, fwp);
	printf("%s\n", obuff);
	fclose(fwp);
	
	free(ibuff);
	free(obuff);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值