Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

EED 1005 Introduction to Programming Preliminary Report 2

Task1

A)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
char day[] = "Friday";
printf ("%s\n", &day[3]);
}
/* 1-The character string we define must be in double quotes
2-In the printf function, the values must be written in double
quotes and the & sign must be used before day[] */

B)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main ()
{
int i=0;
int j=0;
int space = 0;
char cmp[50];
char *p[50] [100];
for (i=0; i< space; i++)
{
for ( j = i + 1;j <=space; j++ )
{
if( (strcmp(p[i], p[j])=0))
{
strcpy(cmp, &p[i]);
strcpy(p[i], p[j]);
strcpy(p[j], cmp);
}
}
}}
/*I can't find it exactly but here is the semicolon error in the
first line
It cannot enter the loop because the space value starts from 0.
and in strcpy & unused */

C)

#include<stdio.h>
#include<string.h>
int main(){
char string[13];
strcpy (string, "Welcome Home");
printf("%s\n",string);

}
/*I just changed the number 12 to 13 because there were 13 values in
total with the number of spaces and we need to write them in double
quotes and
I want the print on the screen*/

D)
#include <string.h>
#include <stdio.h>
int main ()
{

char string[12];
char a[] = "abc";
strcpy(string,a);
printf("%s\n",string);
return 0;

}
/*I couldnt with the pointer and I turn the array.
1- we need add the #include<stdio.h>
2-I crate the new array for de "abc"
3-and I copied this array to string arrayç.*/

Task2)
#include <stdio.h>
#include <stdlib.h>
#define SIZE 100

int main()
{
char str[SIZE]; /* Declares a string of size 100 */
int l= 0;

printf("Input the string : ");


fgets(str, sizeof str, stdin);//I wrote it like this to
evaluate the entered function
while(str[l]!='\0')//I wrote this looped it to stop when there
is a space
{
l++;//it is a counter
}
printf("Length of the string is : %d\n\n", l-1);//it should be
l-1 becasue this code counting in the last space
}

You might also like