#include<stdio.h>
#include<stdlib.h>
int comment1(FILE *fp)
{
char ch;
int count=0;
while(fscanf(fp,"%c",&ch)!=EOF)
{
if(ch=='\n')
{
return count;
}
count++;
}
return count;
}
int comment2(FILE *fp)
{
char ch;
int count=0;
while(fscanf(fp,"%c",&ch)!=EOF)
{
if(ch=='*')
{
fscanf(fp,"%c",&ch);
if(ch=='/')
{
return count;
}
count++;
}
count++;
}
return 0;
}
int main()
{
printf("Enter the file name:");
char s[1000],ch,ch1;
scanf("%s",s);
FILE*fp;
fp = fopen(s,"r");
int count=0;
while(fscanf(fp,"%c",&ch)!=EOF)
{
if(ch=='\"')
{
while(fscanf(fp,"%c",&ch)!=EOF)
{
if(ch=='\"')
{
break;
}
if(ch=='\\')
{
fscanf(fp,"%c",&ch);
}
}
}
else if(ch=='/')
{
fscanf(fp,"%c",&ch);
if(ch=='/')
{
count += comment1(fp);
}
else if(ch=='*')
{
count += comment2(fp);
}
}
}
printf("%d\n",count);
return 0;
}
This is for Python
name = 'Joe'
print(f'My name is {name}')
This is called string formatting. Using f before the text. This is another way
name = 'Joe'
print('My name is', Joe)
But I found that string formatting is cleaner and much more useful
Answer:
Heyy I'm feeling sad and stressed. Wbu?
Explanation:
Answer:
Sharon would need a 'Molex connector' to test the hard drive she is using.
Explanation:
Answer:
C++ code explained below
Explanation:
SOURCE CODE:
*Please follow the comments to better understand the code.
#include <stdio.h>
int numOfBytes(char* string)
{
// initialise the variables
int i=0,size=0;
// while the string reaches to \0, repeat the loop.
while(string[i]!='\0')
{
// add that size
size += sizeof(*string);
// increase the i value.
i++;
}
// add 1 byte for \0
size = size+1;
return size;
}
int main() {
char name[]="Praveen Kumar Reddy";
printf("The size is %d bytes.",numOfBytes(name));
return 0;
}
=============