Qualcomm Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is the code for the same :

#include<stdio.h>
#include<string.h>

void StringCopy(char[], char[]);
int main()
{
char sample[] = " Hello World";
char sampleCopy[20];
int i =0,j=0;
printf("\n The original string is :" );
for(i=0;i<strlen(sample);i++)
{
printf("%c",sample[i]);
}
StringCopy(sample,sampleCopy);

printf("\n The copied string is :");
for(j=0;j<strlen(sampleCopy);j++)
{
printf("%c",sampleCopy[j]);
}
return 0;
}

void StringCopy(char *str1, char *str2)
{

while(*str1 != '\0')
{
*str2++ = *str1++;
}
*str2 = '\0';

}

- AB September 06, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is it code for strncpy or strcpy?

- Balaji March 10, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void strncpy(char*p,char*s,int n) {

for(int i=0;i<n;i++)
*(p+i)=(s+i);
}

- Anonymous March 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Not correct. What if length of s < n? You try to copy over more than required, which might segfault, lead to exploits etc.

More details about the contract of strncpy are needed, though.

- T March 24, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This implement is correct regarding the C/C++ spec.

- Ian F. April 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

From unknown source:

char * 
strncpy( char *dst, const char *src, size_t n )
{
   char *d = dst;
   
   if( n )
   {
      do
      {
          if((*d++ = *src++) == 0)
          {
              while( --n )
                 *d++ = 0;

              break;
          }
      } while ( --n );
   }  /* endof if( n ) */

   return dst;
}

- Anonymous April 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

while(*p++=*s++);

- Anonymous February 18, 2009 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More