commit 2044eba code中文原文

Separating a Ton of Phone Numbers with Commas

Author
Yujia Lin
Date
Reading time
2 min read

Translated from Chinese by Claude. Read the original

Tonight I needed to text more than 50 people, so I thought of Wandoujia. I copied the numbers from Excel into Wandoujia to send them all at once with its group SMS feature. As it turned out, things weren’t as simple as I’d thought.

After copying

I copied from Excel into Notepad, and it pasted the Excel way, as a column, not as a single line. So I copied the column of numbers into Wandoujia, and the result left me shattered…

Not recognized correctly

You can see it says it will be sent to one contact. What now? Was I supposed to add English commas one by one to separate them? I told myself I couldn’t do something that primitive. After all, I’m a code monkey!

Scouting the Way with C, Done in No Time

I know C and Java, but in the end I chose C to write this little program. First you create a character array to hold the huge pile of numbers. Then the whole program works by replacing newline characters with English commas.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <string.h>
define N 100000

int main()

{

FILE *fp;

fp=fopen("Output.txt","w+");

int i=0,j=0;

char a[N],b[N];

scanf("%c",&a[i]);

while(a[i]!='#')

{

i++;
scanf("%c",&a[i]);
}

for(i=0;a[i]!='#';i++)

{

if(strchr(a, '\n')==NULL) //如果查找不到指针值为空,就跳出循环
break;
*(strchr(a, '\n')) = ','; //查找a字符数组中的换行符,返回一个指针
}

for(i=0;a[i]!='#';i++)

{

fputc(a[i],fp);
printf("%c",a[i]);
}

fclose(fp);

return 0;

}

Using C’s file functions, the numbers get written out to Output.txt. Aha! That makes things so much easier.

Esc

Keyboard shortcuts

Ctrl K /
Search and commands
j k
Next or previous post in a list
Enter
Open the selected post
h l
Older or newer post (on a post)
g h
Go to the log
g a
Go to the archive
g t
Go to tags
g s
Go to stats
t
Switch light or dark theme
r
Random post
?
Show this help