-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCFirst.cpp
More file actions
135 lines (116 loc) · 1.58 KB
/
CFirst.cpp
File metadata and controls
135 lines (116 loc) · 1.58 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// CFirst.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#define MAXLINE 1000
int strlen(char s[]);
void strcat(char s[],char t[]);
void squeeze(char s[],char c[]);
int any(char s1[],char s2[]);
int bitcount(unsigned x)
{
int b;
for(b=0;x!=0;x&=(x-1))
{
if(x&01) b++;
}
return b;
}
int getline(char line[],int maxline);
void copy(char to[],char from[]);
void reverse(char input[]);
int _tmain(int argc, _TCHAR* argv[])
{
char target[256]="abcdefghij";
reverse(target);
printf("%s",target);
return 0;
}
void reverse(char input[])
{
int i,j;
i=j=0;
while(input[i++]!='\0')i++;
i-=2;
while (i>=j)
{
char temp=input[i];
input[i]=input[j];
input[j]=temp;
i--;
j++;
}
}
int getline(char s[],int lim)
{
int c,i;
for(i=0;i<lim-1&&(c=getchar())!='&'&&c!='\n';i++)
{
s[i]=c;
}
if(c=='\n')
{
s[i]=c;
i++;
}
s[i]='\0';
return i;
}
void copy(char to[],char from[])
{
int i=0;
int j=0;
while((to[i++]=from[j++])!='\0');
}
int any(char s1[],char s2[])
{
int i,j;
i=j=0;
while (s1[i]!='\0')
{
if(s2[j]=='\0') break;
if(s1[i]==s2[j])
{
j++;
}
else
{
j=0;
}
i++;
}
if(s2[j]=='\0') return i-j;
return -1;
}
bool isin(char s[],char c)
{
int i=0;
while(s[i]!=c&&s[i]!='\0')
{
i++;
}
return s[i]=='\0'?false:true;
}
void squeeze(char s[],char c[])
{
int i,j;
i=j=0;
for(;s[i]!='\0';i++)
{
if(isin(c,s[i])==false)
{
s[j++]=s[i];
}
}
s[j]='\0';
}
void strcat(char s[],char t[])
{
int i,j;
i=j=0;
while(s[i]!='\0')i++;
while ((s[i++]=t[j++])!='\0');
}
int strlen(char s[])
{
return 0;
}