Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

I need help with a script readable from C to gcc

Hey guys and girls, so I just realized i'm stupid. Like really stupid, and wanna kill myself, but before I do that, I need this solved... any help will be wellcome

So I need a script which reads and rewrites a file in .c, and I need to be able to open it with gcc.

I am learning pyton, just started a few days ago, and I understand how to do the rewriter script, and I did it, but I need that script in C, and I need to read it in gcc.

and I have no clue now where to start because I spent a lot of time like an idiot trying to read the python programed script with gcc xD thats why I say im stupid, and I need that for today, and I'm crying.

so this is my python rewriter which i got from a webtutorial while learning.

Code
from sys import argv

script, filename = argv

print "We're going to erase %r." % filename
print "If you don't want that, hit CTRL-C (^C)."
print "If you do want that, hit RETURN."

raw_input("?")

print "Opening the file..."
target = open(filename, 'w')

print "Truncating the file.  Goodbye!"
target.truncate()

print "Now I'm going to ask you for three lines."

line1 = raw_input("line 1: ")
line2 = raw_input("line 2: ")
line3 = raw_input("line 3: ")

print "I'm going to write these to the file."

target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")

print "And finally, we close it."
target.close()

And I need someone smarter than me (not dificult hah) to write that in C, and working in gcc xD

I thx a lot for any help, and yeah.. I will own my life and dignity to the one helping me xD or more than one...

Edit:
the 2 links:
*1
Code
int main(){
  FILE* file = fopen("file.txt","r");
  char * buffer = NULL;
  int i, c;
  c = fgetc(file);
  while(!feof(file))
    {
      buffer = (char*)realloc(NULL, sizeof(char));
        i = 0;
      while( c != '\n')
        {
          buffer[i] = c;
          i++;
          buffer = (char*)realloc(buffer, (i+1)*sizeof(char));
          c = fgetc(file);
        }
      buffer = (char*)realloc(buffer, (i+2)*sizeof(char));
      buffer[i] = c;
      buffer[i+1] = 0;
      printf("%s", buffer);
      free(buffer);
      c = fgetc(file);
    }
  close(file);
}

*2
Code
int wordCounter {
P=0;
for(x=0;x<long;x++){
if(cad[x]==' ' && x!=499 && cad[x+1]!= ' '){
  P++;
  }
}
return 0;
}
I have no idea what you're talking about. You don't "open a file" in GCC. You compile it. GCC is a compiler. What, exactly, are you trying to do?
SRPP Discord Server

I am a professional network/cloud security architect.
My Old Tutorials
(Jan 28, 2016 09:59 AM)Goodies Wrote:  I have no idea what you're talking about. You don't "open a file" in GCC. You compile it. GCC is a compiler. What, exactly, are you trying to do?

He wants to make a program in C that compiles in GCC which will overwrite a given file with 3 lines of input.
Yes, thats what I was trying xD thx for understanding me at least haha
Okay the code is dirty as fuck, the char name[255] are disgusting and shit but it does work

http://pastebin.com/T1fK8S6K

Don't judge me I did it quick
[Image: MtOuiI0.png]
I owe you a big one! thx a lot, really. and I can't apreciate yet if thats disgusting or not hahaha , I find it nice xD

Btw, can you contact me in a PM? wanna negociate maybe xD only if you have 5 minutes time ^^
(Jan 28, 2016 10:06 AM)Annabelle Lee Wrote:  He wants to make a program in C that compiles in GCC which will overwrite a given file with 3 lines of input.

oh... kay...
Idk, OP. Something like this?
PHP Code

<?php 
// Fuck me, HF blocks it. I have to put it in a pastebin. 
http://pastebin.com/ZpMYx94t
SRPP Discord Server

I am a professional network/cloud security architect.
My Old Tutorials
Yes, thats also it haha. You guys are great xD the PM also stands for you Goodies, if you have 5 minutes :3
Let me explain it real quick.

~ Normally, I'd use inline for something like the exists function, but GNU99 inline is not the same as c++ inline.
~ getInput() function will get user input of indeterminate length. If it reaches the end, it will allocate more memory for it. If ever the allocation fails, it will return NULL. This is, I believe, the safest way for an unknown amount string input. Make sure you free() it.
~ It also verifies if you want to overwrite the file.

I don't think it's that ugly.
SRPP Discord Server

I am a professional network/cloud security architect.
My Old Tutorials
I see..
its kinda hard to understand in my position, tbh.. but I think im getting it...

Now i'm trying to do a script which will read and count all the words in a text. kinda tricky, because I don't really understand it yet xD
I wanted some help with that thats why I asked for the pms... but anyways, I got the character counter right xD its this here:

*1 (link edited in the main post)

now I have to get right the word counter. which I have to unify with the character counter xD

and i'm crying because I don't know how to do that xD
thats this here

*2 (link edited in the main port)

I think I need a pause... xD thx a lot for the help
Have you considered using C++? It's going to be considerably easier and not much slower at all.
SRPP Discord Server

I am a professional network/cloud security architect.
My Old Tutorials
but, will I be able to run it in linux? with gcc?
I wrote a mini tool script if that's what you were looking for.(Instructions Inside)

http://pastebin.com/YuQiyf0s

Compile: gcc -o script_file script_file.c
Run: ./script_file [filename] [--w/r/a][/align]

Quote: but, will I be able to run it in linux? with gcc?


Yes you can.
ok, I am learning a lot from this xD and I am sleepy as hell. I thank you a lot guys.

sunrix, your code is really eazy to understand, I will take that one as an example, thx a lot buddy^^ ill try to learn from that one on.

Ill explain exactly what I need now, because I feel I am mixing up stuff and I'm getting kinda sad xD cause I know im not doing a good job at all

1. I need a script which READS and WRITES (copies) a text file word by word

2. I need to use FOPEN to acces the descriptor file

3. I want it to ask me the names of the file which I want to rewrite/read, so that I write the name of the file via keyboard after executing it.

4. to do the reading/writing character by character.

5. get the script to tell me how many words I have in the txt file.

thats what I've been trying to get done xD and I am now full mixed up with a lot of code and I can't get on because I feel like i'm doing it all wrong, so I think i'm going to take a bath and just relax and I get back to work after...

PD: I will gift a full Civ5 key for Steam to whoever answers me with a good answer before 5:30 AM counting that right now is 3:10 AM here. so, ca 2 and half hours after this message is sent

You can see what I've done so far in the other post i've made also here in the C forum section or in the main post of this post, I've edited it. they are the 1* and 2* stars


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by MiguelSanchezApr 3, 2022 02:37 AM 0 101 Apr 3, 2022 02:37 AM
Last Post: MiguelSanchez
[C] by Able.Sep 28, 2021 01:16 PM 5 162 Sep 28, 2021 01:16 PM
Last Post: Donkey Death Jam
[Python] by pmsJun 24, 2019 05:05 PM 5 204 Jun 24, 2019 05:05 PM
Last Post: l0lwtf