1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Please help me with this . Exam Question

Discussion in 'Programming' started by Red_Virus, Oct 16, 2007.

  1. #1
    This is an exam question.. please help me

    
    
    
    
    #include <stdio.h>
    
    int main() {
    
    int i;
    
    char str1[100] = "Good ",
    
    *str2 = "Luck! \n";
    
    
    
    //Add your code here
    
    
    
    printf(str1);
    
    }
    
    
    
    Code (markup):

    Complete the above C program according to the following requirements:

    (a). Access and print the letter "k" in the string pointed by str2 using pointer.

    (b). Concatenate the string pointed by str2 to the end of the string pointed by str1 without using any string operation functions such as strcat().

    Based on the above C code, answer following questions:

    (c). What is the length (number of bytes) of the string pointed by str2?

    (d). Give the UNIX command to generate the .o file from your .c source code. (.o file need not be submitted)

    (e). Give the UNIX command to generate the executable file with debugging information. (executable file need not be submitted)

    Please help me.
     
    Red_Virus, Oct 16, 2007 IP
  2. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What's it worth to ya? Just kidding.

    
    #include <stdio.h>
    
    int main() 
    {
    
    int i;
    
    char str1[100] = "Good ",
    
    *str2 = "Luck! \n";
    
    // (a) print 'k' using pointer notation
    printf("%c\n",*(str2+3));
    
    // (b) concatenate str2 into str1 without using strcat() or strlen()
    for(i=0; str2[i] != 0; i++)
    	str1[5+i] = str2[i];
    str1[5+i]=0; // terminate the string
    
    // (c) length of string pointed to by str2 is now conveniently sitting in i
    printf("%d\n",i);
    
    printf(str1);
    
    // (d) to compile into an object file with debug info: gcc -c -g  exam.c -o exam.o
    
    // (e) to generate an executable with debug info from the above object file: gcc -g exam.o -o exam
    
    }
    
    Code (markup):
     
    sea otter, Oct 16, 2007 IP
  3. Red_Virus

    Red_Virus Well-Known Member

    Messages:
    3,756
    Likes Received:
    249
    Best Answers:
    0
    Trophy Points:
    135
    #3
    Thanks so much buddy for helping me out with the solution to this problem.

    Amit :)
     
    Red_Virus, Oct 17, 2007 IP
  4. gsfl4u2

    gsfl4u2 Banned

    Messages:
    1,418
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    43
    #4
    wow..unreal i just want to say This FOrum Rocks..i mean where else can someone get help like this..I love it here
     
    gsfl4u2, Oct 17, 2007 IP
  5. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ah, no prob. DP can be pretty tough, but the programming forums here are cool.
     
    sea otter, Oct 17, 2007 IP