LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-01-2009, 06:46 AM   #1
a2.utami
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Rep: Reputation: 0
running c in linux


hi all,

I have a code written in C (file = reverse.c) and I compiled it in linux with gcc and saved as reverse.
now i wanna run it to reverse an image yrgnuh.gpj. when i typed ./reverse yrgnuh.gpj hungry.jpg, it didnt give me any error message but i couldnt find hungry.jpg anywhere.

any help is appreciated
 
Old 04-01-2009, 06:56 AM   #2
maxy7710
Member
 
Registered: Jan 2008
Location: Mumbai, india
Distribution: REDHAT, FEDORA,SUSE, UBUNTU, ORACLE ENTERPRISE LINUX & SOLARIS 10
Posts: 130

Rep: Reputation: 17
can you post u r script for further details
 
Old 04-01-2009, 07:04 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Welcome to LQ!!

It is April 1, so I suppose you might be funnin' us.....

The reverse of "yrgnuh.gpj" is "jpg.hungry"---n'est-ce pas? (No--Wait--You are reversed: sap ec-tse'n?)
 
Old 04-02-2009, 03:35 AM   #4
a2.utami
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Original Poster
Rep: Reputation: 0
this is the source code:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int i, n;
FILE *f;
char *b, *c;
f = fopen(argv[1], "r+");
if (f == NULL) { fprintf(stderr, "invalid file.\n"); exit(1); }
fseek(f, 0, SEEK_END);
n = ftell(f);
b = malloc(n);
if (b == NULL) { fprintf(stderr, "malloc() failed.\n"); exit(1); }
rewind(f);
fread(b, 1, n, f);
c = malloc(n);
if (c == NULL) { fprintf(stderr, "malloc() failed.\n"); exit(1); }
for (i=0; i<n; i++) c[i] = b[n-i-1];
rewind(f);
fwrite(c, 1, n, f);
fclose(f);
free(b);
free(c);
return 0;
}
 
Old 04-02-2009, 03:45 AM   #5
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
IIRC, argv[1] is the first argument passed (argv[0] being the program name), so from the code, I can't see that hungry.jpg (or any second argument) is being used.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows running Firefox more secure than linux running it? moxieman99 General 14 04-04-2009 10:12 AM
Problems installing and running Frostwire on Acer One running Linpus Linux ricky1981 Linux - Newbie 1 12-19-2008 08:24 AM
Access for Multiple Linux servers from any cilent node running REDHAT LINUX 9 bv_uma Linux - Server 2 08-18-2006 12:17 AM
any linux distro can running in RAM , not need CD_ROM reading when running. wangcity Linux - General 3 09-18-2003 05:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration