473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Can someone explain the misbehaviour of this code

I was trying to solve a problem but the problem is the string a is disappearing at the end of for loop.
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<string.h>
  3. int main()
  4. {
  5.         int i,t,j;
  6.         char a[10],b[10];
  7.         scanf("%d",&t);
  8.         for(i=0;i<t;i++)
  9.         {
  10.                 int c=0;
  11.                 scanf("%s %s",a,b);
  12.  
  13.                 for(j=0;j<strlen(a);j++)
  14.                 {        
  15.                         printf("%s",a);\\printing string here gives the string 
  16.                         if((a[j]=!b[j])&&(a[j]!='?')&&(b[j]!='?'))
  17.                         {
  18.                                 printf("No\n");
  19.                                 break;
  20.                         }
  21.                         else
  22.                         {
  23.                                 c++;
  24.                         }
  25.                        printf("%s",a);\\printing here is not giving the string
  26.                 }
  27.               if(c==strlen(a))
  28.                 printf("Yes\n");
  29.         }
  30. }
  31.  
  32.  
  33.  
  34.  
Aug 23 '15 #1

✓ answered by weaknessforcats

Check this line of code:

Expand|Select|Wrap|Line Numbers
  1. if((a[j]=!b[j])&&(a[j]!='?')&&(b[j]!='?'))
  2.  
There is no =! operator. You meant to use !=. That =! will act as an assignment operator and will assign !b[j] to a[j].

Every time b[j] is true (not zero), then zero will be assigned to a[j]. That assigned zero will act as a null terminator making your string disappear.

1 1179
weaknessforcats
9,208 Expert Mod 8TB
Check this line of code:

Expand|Select|Wrap|Line Numbers
  1. if((a[j]=!b[j])&&(a[j]!='?')&&(b[j]!='?'))
  2.  
There is no =! operator. You meant to use !=. That =! will act as an assignment operator and will assign !b[j] to a[j].

Every time b[j] is true (not zero), then zero will be assigned to a[j]. That assigned zero will act as a null terminator making your string disappear.
Aug 24 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Maciej Nadolski | last post by:
Hi! I can`t understand what php wants from me:( So: Cannot send session cache limiter - headers already sent (output started at /home/krecik/public_html/silnik.php:208) in...
2
by: rked | last post by:
I get nameSPAN1 is undefined when I place cursor in comments box.. <%@ LANGUAGE="VBScript" %> <% DIM ipAddress ipAddress=Request.Servervariables("REMOTE_HOST") %> <html> <head> <meta...
5
by: J Allen Horner | last post by:
I'm just starting to learn C, and the tutorial I'm reading uses this code as an example: ----------- #include <stdio.h> #define MAX 10 int a; int rand_seed=10;
3
by: Lenn | last post by:
Hello, I have the following example of AsyncCallback from a C# book which I wanted to implement in my project: //Class with AsyncDelegate public class AsyncProcess { public AsyncProcess() {
1
by: Tran Hong Quang | last post by:
Hi, In header file, I see this declaration: #define DECLARE_VTBL(iname) iname vt##iname; then, in C file, there are below codes: typedef struct _Abc { .......... } abc;
8
by: Beany | last post by:
I managed to find a search example on the forum but i dont understand the following code properly........ can someone explain this to me: Private Sub QuickSearch_AfterUpdate() ...
5
by: Nhd | last post by:
#include <iostream> #include <sstream> #include <string> using namespace std; int main(int argc, char* argv) { int Count1 = 1; int Count2 = 1; int Count = 0;
10
by: jinnejeevansai | last post by:
I was writing a code to create posix threads print function is printing p,q for 4 loops but it is not printing for fifth loop but the loop is called. Can someone explain the reason. ...
1
by: jinnejeevansai | last post by:
I was trying to write a program to copy data in one file to another file,but my code was not responding,it was asking for input,can someone explain the problem in my code. #include<stdio.h>...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.