What is the significance of int argc & char *argv[] ? Where and why is it used ?
What is the significance of int argc & char *argv[] ? Where and why is it used ?
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<signal.h>
void outch(int sig)
{
printf(“outch:i got a signal no.=%d\n”,sig);
sleep(5);
printf(“handler for signal no.=%d has ended\n”,sig);
}
int main()
{
struct sigaction act,act1;
act.sa_handler=outch;
sigemptyset(&act.sa_mask);
sigaddset(&act.sa_mask,SIGQUIT);
sigaction(SIGINT,&act,0);
sigaction(SIGQUIT,&act,0);
act1.sa_handler=outch;
sigemptyset(&act1.sa_mask);
sigaddset(&act1.sa_mask,SIGTSTP);
sigprocmask(SIG_BLOCK,&act1.sa_mask,&act.sa_mask);
while(1)
{
printf(“hello\n”);
sleep(1);
}
return 0;
}
in the above prog. SIG_BLOCK is not doing union of old & new mask.
[Japjeet@localhost build-boot-gcc]$ ../gcc-2.95.3/configure –target=$TARGET –prefix=${PREFIX} –disable-shared –with-headers=${TARGET_PREFIX}/include –with-newlib –enable-languages=c
Following Error occur:
Config.guess failed to determine the host type. You need to specify one.
Usage: configure [OPTIONS] [HOST]
Options: [defaults in brackets]
–prefix=MYDIR install into MYDIR [/usr/local]
–exec-prefix=MYDIR install host-dependent files into MYDIR [/usr/local]
–help print this message [normal config]
–build=BUILD configure for building on BUILD [BUILD=HOST]
–host=HOST configure for HOST [determined via config.guess]
–norecursion configure this directory only [recurse]
–program-prefix=FOO prepend FOO to installed program names [""]
–program-suffix=FOO append FOO to installed program names [""]
–program-transform-name=P transform installed names by sed pattern P [""]
–site=SITE configure with site-specific makefile for SITE
–srcdir=DIR find the sources in DIR [. or ..]
–target=TARGET configure for TARGET [TARGET=HOST]
–tmpdir=TMPDIR create temporary files in TMPDIR [/tmp]
–nfp configure for software floating point [hard float]
–with-FOO, –with-FOO=BAR package FOO is available (parameter BAR)
–without-FOO package FOO is NOT available
–enable-FOO, –enable-FOO=BAR include feature FOO (parameter BAR)
–disable-FOO do not include feature FOO
Where HOST and TARGET are something like “sparc-sunos”, “mips-sgi-irix5″, etc.
#!/bin/sh
# This file was generated automatically by configure. Do not edit.
# This directory was configured as follows:
../gcc-2.95.3/configure –with-gcc-version-trigger=/home/Japjeet/control-project/daq-module/build-tools/gcc-2.95.3/gcc/version.c –host=i686-pc-linux-gnu –target=arm-linux –prefix=/home/Japjeet/control-project/daq-module/tools –without-headers –with-newib –enable-languages=c –norecursion
# using “mt-frag”
*******************************************************************************
When i determine the host type like [Japjeet@localhost build-boot-gcc]$ ../gcc-2.95.3/configure –host=i686-pc-linux-gnu –target=$TARGET –prefix=${PREFIX} –disable-shared –with-headers=${TARGET_PREFIX}/include –with-newlib –enable-languages=c
Following error occur:
Copying /home/Japjeet/control-project/daq-module/tools/arm-linux/include to /home/Japjeet/control-project/daq-module/tools/arm-linux/sys-include
Created “Makefile” in /home/Japjeet/control-project/daq-module/build-tools/build-boot-gcc using “mt-frag”
/home/Japjeet/control-project/daq-module/tools/arm-linux/bin/ld: cannot open crt1.o: No such file or directory
collect2: ld returned 1 exit status
*** The command ‘arm-linux-gcc -o conftest -g -O2 conftest.c’ failed.
*** You must set the environment variable CC to a working compiler.
Operators of the same priority are evaluated from left to right, so that Operators of the same priority are evaluated from left to right, so that
a – b – c
is evaluated as
( a – b ) – c ????????????????????/
//
// Reading a txt File using Pointers
//
#include<stdio.h>
#include<stdlib.h> // Header File For malloc
FILE *fptr;
char *ch;
int ret,ret2;
int main()
{
printf(“\n”);
fptr = fopen(“f1.txt”,”r”);
if (fptr == NULL)
{
printf(“Error Opening File”);
}
else {
printf(“File Found”);
}
fseek(fptr,0,SEEK_END);
ret2 = ftell(fptr);
ch =(char *) malloc(ret2);
fseek(fptr,0,SEEK_SET);
printf(“\n%d bytes of data is present in the file\n”,ret2);
ret = fread(ch,1,ret2,fptr);
printf(“\nData in File :\n%s”,ch);
printf(“\nNo of Characters read from File : %d”,ret);
printf(“\n\n”);
return 0;
}
Code is working fine… but the problem is it still works with
ch =(char *) malloc(1);
Why ???
Which is/are the type/s of memory allocation that needs/need the programmer to take
care of memory management?
1. Static memory allocation //true or false
2. Dynamic memory allocation //true or false
3. Automatic memory allocation //true or false
4. Memory allocation on stack //true or false
5. Memory allocation on heap //true or false
Dear All!!
I have done this assignment but Ain’t satisfying. I want code optimization.
Assignment No. =>005_16(Q.No.17) Write a program to find the number of times that a given word(i.g a short string) occurs in a sentence (i.e. a long string!). Read data from standard input. The first line is a single word, which is followed by general text on the second line. Read both up to a newline character, and insert a terminating null before processing. Typical output should be:
The word is “the”. //should be any word
The sentence is “the cat sat on the mat”. //can be any sentence
The word occurs 2 times.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int search(char *, char *);
int main()
{
/*’word’ input from user*/
char *ch=0;
int i;
printf(“Enter \’word\’\n”);
ch=(char *)malloc(sizeof(char)*100);
fgets(ch,100,stdin);
/*input String*/
printf(“Enter \’Sentence\’\n”);
char *str=0;
str=(char *)malloc(sizeof(char)*100);
fgets(str,100,stdin);
i=strlen(str);–i;
str[i] = ‘ ‘;++i;
str[i] = ”;
search(ch,str);
return 0;
}
int search(char *ch, char *str)
{
int i=0,j=0,count=0;
while((*(str+i))!=”)
{
if(((*(str+i)) == (*(ch+j))) || (((*(str+i)) == ‘ ‘) && ((*(ch+j)) == 10)))
{
if(((*(str+i))== ‘ ‘) && ((*(ch+j))==10))
{
count++;
j=-1;
}
j++;
}
else
{
for(i;(*(str+i) != ‘ ‘);i++)
if((*(str+i))==10)
break;
}
i++;
}
printf(“The word occurs %d times \n”,count);
}
Dear all
In question no. 12 of assignment Ist
int ten =10;
int two=2;
printf(“%d minus%d=%d\n”,ten);
printf(“%dminus %d=%d\n”,ten,2,ten-two);
printf(“%dminus%d is %d\n”,ten);
return 0;
i was surprised to c the result of 3rd printf statement. Ist and IInd printf statemnt result was OK. but third print statement was unexpected…can anybody tell me the reason???
??how char can be signed / unsigned ???
how can we define a negative char ….
and why we need negative char ?
hi,
I have installed the fedora than updated the kernel.
In my desktop the LAN port was not identified by the OS, so I have downloaded it but when I try to call make command. I got this error.
makefile 105: linux kernel source not configured missing autoconf.h fadora
Note: If I use the driver without upgrading the kernel it works fine.
Hi All,
in the following program I have observed that the program is not jumped on the handler but if i remove the statement sleep(1); it work fine.
the piece of the code is
…
while(1)
{
if (flag)
printf(“waiting for signal”);
else
printf(“signal invoked”);
sleep(1);
}
my question is when we press Ctrl+C (generating a signal) in such case the program should moved to signal handler function but in this case why it is not working correctly while having sleep(1); statement there why it is so?
int ret = execl(“./pipe2.c”,”pipe2.c”,”A”,(char *)0);
if(ret < 0)
{perror(“EXECL”); exit(EXIT_FAILURE); }
}
on execution i am getting EXEC: Exec format error
?? why
Here is my source code —-
#include
#include
#include
#include
#include
#include
#ifndef DEBUG
#define DEBUG
#endif
MODULE_LICENSE(“GPL”);
MODULE_AUTHOR(“VAIBHAV”);
MODULE_DESCRIPTION(“Simple Modules init and exit”);
static short int data=4;
static int i=2;
static long int j=1;
static char *si=” vaibhav “;
static int pvtdata __initdata=1234;
static int __init vaibhav(void)
{
#ifdef DEBUG
printk(KERN_INFO “Begin !%s \n”,__func__);
#endif
#ifdef DEBUG
printk(KERN_ALERT “hello kernel !\n”);
#endif
#ifdef DEBUG
printk(KERN_ALERT “data=%d \t i=%d \t j=%ld\t si=%s\t pvtdata=%d\n”,data,i,j,si,pvtdata);
#endif
#ifdef DEBUG
printk(KERN_ALERT “The process is %s and its pid is %d \n”,current->comm,current->pid );
#endif
#ifdef DEBUG
printk(KERN_INFO “%s End\n”,__func__);
#endif
return 0;
}
module_init(vaibhav);
module_param(data,short,S_IRUGO);
module_param(i,int,S_IRUGO );
module_param(j,long,S_IRUGO);
module_param(si,charp,S_IRUGO);
module_param(pvtdata,int,S_IRUGO);
static void __exit vaibhav1(void)
{
#ifdef DEBUG
printk(KERN_INFO “Begin !%s \n”,__func__);
#endif
#ifdef DEBUG
printk(KERN_ALERT “Execution compleate \n”);
#endif
#ifdef DEBUG
printk(KERN_INFO “%s End \n”,__func__);
#endif
}
module_exit(vaibhav1);
FTP requires two computers, one running an FTP server, the other running an FTP client. The exchange is initiated by the client which logs in under an accepted user name and password. Once this occurs, a session is opened and stays open until closed by either the client or the server, or until it times out. While the session is open, the client may execute numerous FTP commands on the server. These include commands to change directories, list files, get files and put files.
What is the difference between passive and active FTP?
FTP is an unusual protocol in that it uses two ports, one for commands and the other for data. (This is one of the reasons it is superior to HTTP for transferring large files.) Active FTP was invented first. The client initiates a connection on the server’s command port. The server then initiates a connection with the client from its data port. In Passive FTP, the client initiates both connections with the server, which remains “passive”.
Active FTP may cause problems if your client is behind a firewall. From the firewall’s point of view, the FTP server that is trying to initiate a connection with your client looks like an intruder and is usually blocked. This is why many users have difficulty using FTP to download files from behind a firewall.
Passive FTP solves this problem, but creates other problems, notably where FTP server security is concerned. The server must listen on a large number of ports. This requires the firewall to let a lot of unqualified traffic through. Most firewall administrators do not like this.
As a rule, you do not need to be concerned about passive and active FTP unless you administer an FTP server or a firewall. If you experience difficulty using your FTP client from behind a firewall, this is likely the reason. Perhaps you should discuss the matter with your firewall administrator.
Is FTP better than HTTP for downloading files?
Yes, as a matter of fact it is. HTTP is designed to fetch web pages. It is optimized for numerous repeated fetches of small items. FTP is designed for transferring files, and offers faster overall throughput and better error checking. It is not uncommon for a user to fail repeatedly to download a large file via HTTP using their browser, only to succeed on their first try using a dedicated FTP client. If you download large files frequently, and experience difficulties, get a dedicated FTP client software program.
What is anonymous FTP?
FTP requires the client program to log into the server program identifying themselves with a user name and authenticating themselves with a password. Many FTP sites exist however, that freely offer data to the public. In order to comply with FTP’s requirement that a session be opened with a user name and a password, these sites operate what is known as “anonymous FTP”. This involves using a generic user whose name is “anonymous” and who will accept any syntactically valid email address as a password. It enables the server to distinguish between users, since email addresses are always unique, yet allows all users to log in under the common user name “anonymous”.