[Sample] Merge two files

Discussion in 'iOS Development' started by gojohnnyboi, Feb 22, 2009.

Thread Status:
Not open for further replies.
  1. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Okay, i wrote this because i needed to merge two files i had into one file. the objective here was for only me to be able to access the files, because to split them, you would have to know how many bytes the two individual files were. this prevents people from looking at/changing your files.

    so, why not post the source eh?

    Code:
    #include <iostream>
    #include <fstream>
    #include <sys/stat.h>
    
    using namespace std;
    
    int main(int argc, const char *argv[]) {
    	struct stat _file;
    	struct stat _file2;
    	struct stat _mergedFile;
    	
    	if(argv[1] != NULL && argv[2] != NULL && argv[3] != NULL) {
    		
    		if((stat(argv[1], &_file) || stat(argv[2], &_file2)) == 0) {
    			printf("\nSize of %s: %lld Bytes\n", argv[1], (long long)_file.st_size);
    			printf("Size of %s: %lld Bytes\n\n", argv[2], (long long)_file2.st_size);
    			
    			fstream file_1;
    			fstream file_2;
    			ofstream file_3;
    			
    			FILE *checkExists;
    			checkExists = fopen(argv[3], "rw");
    			if(checkExists != NULL) {
    				printf("Destination file already exists.\n");
    				fclose(checkExists);
    				return 0;
    			}
    			
    			fclose(checkExists);
    				
    			file_1.open(argv[1], ios::in	| ios::binary);
    			file_2.open(argv[2], ios::in	| ios::binary);
    			file_3.open(argv[3], ios::out	| ios::binary);
    						
    			if(!file_1 || !file_2 || !file_3) {
    				printf("Failed to open file(s)\n");
    				return 0;
    			} else {
    				printf("Setup Complete\n");
    				
    				
    				char _filePart_1;
    				char _filePart_2;
    				
    				file_1.get(_filePart_1);
    				
    				while(!file_1.eof()) {
    					file_3.put(_filePart_1); 
    					file_1.get(_filePart_1);
    				}
    				
    				file_2.get(_filePart_2);
    				
    				while(!file_2.eof()) {
    					file_3.put(_filePart_2); 
    					file_2.get(_filePart_2);
    				}
    				
    				printf("Files Merged\n");
    				
    				file_1.close();
    				file_2.close();
    				file_3.close();
    				
    				if(stat(argv[3], &_mergedFile) == 0) {
    				   printf("\nSize of new file %s: %lld Bytes\n\n", argv[3], (long long)_mergedFile.st_size);
    				} else {
    				   printf("Error reading new file size\n\n");
    					return 0;
    				}
    			}
    		} else {
    			printf("Files do not exist\n");
    			return 0;
    		}
    	} else {
    		printf("Usage: %s <filename> <filename> <destination>\n", argv[0]);
    		return 0;
    	}
    			   
    	return 0;
    }
    
    if you understand what is happening here, it shouldn't be hard for you to reverse it; just remember how many bytes the files were individually.
  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Clearly a copy and paste job:


    EDIT: At least give credit to the sources, where credit is due.
  3. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    right...im sure. no actually, it's not. and for credit to sources whatever the hell you said, i'm not even sure what you mean.
    ------------------double post merged------------------
    if you must know why both are there, i'll tell you.

    when i was doing ios::binary etc, the compiler was telling me that ios wasn't declared, so naturally i was like wtf? silly me, i forgot to do namespace std, which fixed my problem. however, before that i was trying stuff, and i put that there.
  4. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    If you don't know what I mean, than that is said.

    No, they're both there because you cobbled some code together and are trying to pass it off as your own.

    Let's save time and have condense what this thread will most likely be down to one post. I'll start off by saying that you steal code from the internet, apply some changes and call it your own all the while taking all kinds of adulation from people that think you know what you are doing. I'll point to your source code and the incongruities , the inconsistencies, and the mismatches within your code.

    I'll further state that your understanding isn't as deep as you think it is, but rather wide and shallow: evidenced by the fact that you like to gloat equally about every thing you do: insignificant things get equal self lauding as large things that you do.

    You will deny this, maybe get argumentative (and that's okay). You may post code samples of your own, but that will be irrelevant. You may post code samples of mine, and that will also be irrelevant, as I don't claim to be anything of a coder at all. I never have. Regardless, it will be moot, as I don't care.

    If I'm feeling especially like a jerk, I'll pull some irc logs where you ask some question, get told an answer or get corrected about something, then come right on here and state what you just found out as if it were the basest of facts that you've always known. Those are time stamped; so are your posts.

    You might respond, but by that time, I'd long have lost interest, so I won't respond. You'll take from that what you will, and it won't bother me in the least.

    Really, settle down a bit and don't take yourself so seriously. There's not a thing you've done that hundreds can't also do (better). Likewise, there's not a thing I've done that hundreds of others can't do (better). Just, do the right thing, and when you steal, borrow, or otherwise obtain code, do the original coders a favor and give them some credit.

    Now, I've said all there is to say, I'm done. Continue on basking in your unwarranted acclaim.
  5. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    I realize this can be perceived as flaming, so will another mod please infract me. Fair is fair, after all.
  6. Teslanaut

    Teslanaut Well-Known Member

    Joined:
    Sep 16, 2007
    Messages:
    15,588
    Likes Received:
    177
    Device:
    4G iPod touch
    I don't see anywhere where you flame him whatsoever. You're just telling him to be more truthful about the code that he uses and that he should be more humble about how he perceives himself and how he places himself in front of people.
  7. spykr

    spykr Banned

    Joined:
    Jan 4, 2009
    Messages:
    109
    Likes Received:
    0
    Holy sh*t, it's about time someone did that

    Please Register or Log in to view images

  8. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    SkylarEC,

    I do not wish to fight with you. So, in response to your above post, I'm going to tell you the complete and honest truth. The ONLY person who helped me with this program was a man named Jake Wolpert. He has the name jakecigar on the forums here. He is a professional coder, that's his career.

    So yes, credit to him.

    Also, about you saying me bragging, etc: I'm not going to argue, I get over excited when I can produce a program that does something cool, and I do feel confident. I DO in fact at times brag about things where I completely shouldn't, and I am aware of that. I am a human being, therefore I have flaws, as anyone else does.

    About stealing code: No, I do not steal code. When I do use other people's code, it's because I have permission, or the license it's released under does in fact allow it to be forked, and even then I give credit to the original code makers.

    When I fail to do things like that, you must understand that it's not on purpose. I value the hard work it takes to make stuff like this, and respect fellow programmers such as yourself.


    -John


    EDIT: I may have in fact used code without permission in the past, and don't even remember it and even realize it at the time, which may be what you're talking about, and I know I am not as advanced of a programmer you are, but I am making a solid attempt to learn. I love working with computers; it is my passion and I plan to go to college for it.
  9. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    You don't flame there what so ever Skylar, your just stating your opinion. But it takes an honest man to live up to his wrong doings.
  10. bgizzle

    bgizzle Administrator Staff Member

    Joined:
    Sep 13, 2007
    Messages:
    5,100
    Likes Received:
    543
    Device:
    iPhone 6
    i do not consider this flaming in the least. that being said, i will close this thread to avert an potential problems.
Thread Status:
Not open for further replies.

Share This Page