Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; even without the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- All code posted on my Pastebin is designed for Linux (Debian-based)
- compile with: gcc charnum.c -o charNum
- A program to determine how many characters are in a file
- (such as .C, .py, .txt, etc...)
- Note: Does not include newline characters
- Original creator: 0x00sec_JINX (https://0x00sec.org/users/0x00_jinx)
- */
- #include <stdio.h>
- #include <strings.h>
- #include <unistd.h>
- int main(int argc, char *argv[]){
- if(argc != 2){
- printf("Usage: %s <filename>\n",argv[0]);
- return 1;
- }
- FILE *fd;
- char buff[2];
- int charCount = 0;
- if((fd = fopen(argv[1],"r")) < 0){
- printf("ERROR Could not open file %s",argv[1]);
- return 1;
- }
- while((fgets(buff,sizeof(buff),(FILE*)fd)) != NULL){
- if((buff[1] != '\n') && (buff[0] != '\n')){
- ++charCount;
- }
- }
- fclose(fd);
- printf("%d\n",charCount);
- return 0;
- }
Add Comment
Please, Sign In to add comment