-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc_code_shortener.py
More file actions
22 lines (22 loc) · 1.06 KB
/
c_code_shortener.py
File metadata and controls
22 lines (22 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
mk=""
hello=""
count=0
file1=input("Input the file location : ")#File location of the C source code which needs to be shortened
with open(file1) as data:
for line in data:
if(line[:-1] == "#include<stdlib.h>" or line[:-1] == "#include<stdio.h>" or line[:-1] =="#include <stdlib.h>" or line[:-1] =="#include <stdio.h>" or line[:-1] =="#include <string.h>" or line[:-1] == "#include<string.h>" or line[:-1] == "#include<ctype.h>" or line[:-1]=="#include <ctype.h>"):
hello=hello+line[:-1]+"\n"
else:
if(line[0:3]==4*" "):
line=line[0:3]
for k in line:
if(k!=';' and k!=' ' and k!='\n'):
mk=mk+k
elif(k==';' and k!=' ' and k!='\n'):
mk=mk+';'
mk=hello+mk
print(mk,"\n\nThe Shortened c source code will be saved in 1.c ")
file2 = open("1.c","w")#The shortened c source code will be saved in 1.c
file2.write(mk)
file2.close()
print("\n\n1.c file created\n\n")#Anything which is present in 1.c will be erased and new shortened code will added